99using System . IO ;
1010using System . Linq ;
1111using System . Reactive . Linq ;
12+ using System . Runtime . InteropServices ;
1213using System . Threading . Tasks . Dataflow ;
1314using Microsoft . Azure . WebJobs . Logging ;
1415using Microsoft . Azure . WebJobs . Script . Description ;
1516using Microsoft . Azure . WebJobs . Script . Diagnostics ;
1617using Microsoft . Azure . WebJobs . Script . Eventing ;
1718using Microsoft . Azure . WebJobs . Script . Eventing . Rpc ;
1819using Microsoft . Azure . WebJobs . Script . Grpc . Messages ;
20+ using Microsoft . Azure . WebJobs . Script . ManagedDependencies ;
1921using Microsoft . Extensions . Logging ;
22+ using Microsoft . Extensions . Options ;
23+ using Newtonsoft . Json ;
2024
2125using FunctionMetadata = Microsoft . Azure . WebJobs . Script . Description . FunctionMetadata ;
2226using MsgType = Microsoft . Azure . WebJobs . Script . Grpc . Messages . StreamingMessage . ContentOneofCase ;
@@ -52,6 +56,7 @@ internal class LanguageWorkerChannel : ILanguageWorkerChannel
5256 private IDisposable _startSubscription ;
5357 private IDisposable _startLatencyMetric ;
5458 private Uri _serverUri ;
59+ private IOptions < ManagedDependencyOptions > _managedDependencyOptions ;
5560
5661 internal LanguageWorkerChannel ( )
5762 {
@@ -71,7 +76,8 @@ internal LanguageWorkerChannel(
7176 IMetricsLogger metricsLogger ,
7277 int attemptCount ,
7378 ILanguageWorkerConsoleLogSource consoleLogSource ,
74- bool isWebHostChannel = false )
79+ bool isWebHostChannel = false ,
80+ IOptions < ManagedDependencyOptions > managedDependencyOptions = null )
7581 {
7682 _workerId = workerId ;
7783 _functionRegistrations = functionRegistrations ;
@@ -104,6 +110,7 @@ internal LanguageWorkerChannel(
104110 . Subscribe ( ( msg ) => InvokeResponse ( msg . Message . InvocationResponse ) ) ) ;
105111
106112 _startLatencyMetric = metricsLogger ? . LatencyEvent ( string . Format ( MetricEventNames . WorkerInitializeLatency , workerConfig . Language , attemptCount ) ) ;
113+ _managedDependencyOptions = managedDependencyOptions ;
107114 }
108115
109116 public string Id => _workerId ;
@@ -343,6 +350,12 @@ internal void SendFunctionLoadRequest(FunctionRegistrationContext context)
343350 }
344351 } ;
345352
353+ if ( _managedDependencyOptions ? . Value != null )
354+ {
355+ _workerChannelLogger ? . LogInformation ( $ "Adding dependency download request to { _workerConfig . Language } language worker") ;
356+ request . ManagedDependencyEnabled = _managedDependencyOptions . Value . Enabled ;
357+ }
358+
346359 foreach ( var binding in metadata . Bindings )
347360 {
348361 BindingInfo bindingInfo = binding . ToBindingInfo ( ) ;
@@ -363,6 +376,12 @@ internal void LoadResponse(FunctionLoadResponse loadResponse)
363376 //Cache function load errors to replay error messages on invoking failed functions
364377 _functionLoadErrors [ loadResponse . FunctionId ] = ex ;
365378 }
379+
380+ if ( loadResponse . IsDependencyDownloaded )
381+ {
382+ _workerChannelLogger ? . LogInformation ( $ "Managed dependency successfully downloaded by the { _workerConfig . Language } language worker") ;
383+ }
384+
366385 var inputBuffer = _functionInputBuffers [ loadResponse . FunctionId ] ;
367386 // link the invocation inputs to the invoke call
368387 var invokeBlock = new ActionBlock < ScriptInvocationContext > ( ctx => SendInvocationRequest ( ctx ) ) ;
0 commit comments