@@ -30,17 +30,15 @@ public class FunctionMetadataManager : IFunctionMetadataManager
3030 private bool _servicesReset = false ;
3131 private ILogger _logger ;
3232 private IOptions < ScriptJobHostOptions > _scriptOptions ;
33- private IOptionsMonitor < LanguageWorkerOptions > _languageWorkerOptions ;
3433 private ImmutableArray < FunctionMetadata > _functionMetadataArray ;
3534 private Dictionary < string , ICollection < string > > _functionErrors = new Dictionary < string , ICollection < string > > ( ) ;
3635 private ConcurrentDictionary < string , FunctionMetadata > _functionMetadataMap = new ConcurrentDictionary < string , FunctionMetadata > ( StringComparer . OrdinalIgnoreCase ) ;
3736
3837 public FunctionMetadataManager ( IOptions < ScriptJobHostOptions > scriptOptions , IFunctionMetadataProvider functionMetadataProvider ,
3938 IOptions < HttpWorkerOptions > httpWorkerOptions , IScriptHostManager scriptHostManager , ILoggerFactory loggerFactory ,
40- IOptionsMonitor < LanguageWorkerOptions > languageWorkerOptions , IEnvironment environment )
39+ IEnvironment environment )
4140 {
4241 _scriptOptions = scriptOptions ;
43- _languageWorkerOptions = languageWorkerOptions ;
4442 _serviceProvider = scriptHostManager as IServiceProvider ;
4543 _functionMetadataProvider = functionMetadataProvider ;
4644 _loggerFactory = loggerFactory ;
@@ -84,11 +82,11 @@ public bool TryGetFunctionMetadata(string functionName, out FunctionMetadata fun
8482 /// <param name="applyAllowList">Apply functions allow list filter.</param>
8583 /// <param name="includeCustomProviders">Include any metadata provided by IFunctionProvider when loading the metadata</param>
8684 /// <returns> An Immmutable array of FunctionMetadata.</returns>
87- public ImmutableArray < FunctionMetadata > GetFunctionMetadata ( bool forceRefresh , bool applyAllowList = true , bool includeCustomProviders = true )
85+ public ImmutableArray < FunctionMetadata > GetFunctionMetadata ( bool forceRefresh , bool applyAllowList = true , bool includeCustomProviders = true , IList < RpcWorkerConfig > workerConfigs = null )
8886 {
8987 if ( forceRefresh || _servicesReset || _functionMetadataArray . IsDefaultOrEmpty )
9088 {
91- _functionMetadataArray = LoadFunctionMetadata ( forceRefresh , includeCustomProviders ) ;
89+ _functionMetadataArray = LoadFunctionMetadata ( forceRefresh , includeCustomProviders , workerConfigs : workerConfigs ) ;
9290 _logger . FunctionMetadataManagerFunctionsLoaded ( ApplyAllowList ( _functionMetadataArray ) . Count ( ) ) ;
9391 _servicesReset = false ;
9492 }
@@ -114,28 +112,37 @@ private void InitializeServices()
114112
115113 _isHttpWorker = _serviceProvider . GetService < IOptions < HttpWorkerOptions > > ( ) ? . Value ? . Description != null ;
116114 _scriptOptions = _serviceProvider . GetService < IOptions < ScriptJobHostOptions > > ( ) ;
117- _languageWorkerOptions = _serviceProvider . GetService < IOptionsMonitor < LanguageWorkerOptions > > ( ) ;
118115
119116 // Resetting the logger switches the logger scope to Script Host level,
120117 // also making the logs available to Application Insights
121118 _logger = _serviceProvider ? . GetService < ILoggerFactory > ( ) . CreateLogger ( LogCategories . Startup ) ;
122119 _servicesReset = true ;
123120 }
124121
122+ /// <summary>
123+ /// This is the worker configuration created in the jobhost scope during placeholder initialization
124+ /// This is used as a fallback incase the config is not passed down from previous method call.
125+ /// </summary>
126+ private IList < RpcWorkerConfig > GetFallbackWorkerConfig ( )
127+ {
128+ return _serviceProvider . GetService < IOptionsMonitor < LanguageWorkerOptions > > ( ) . CurrentValue . WorkerConfigs ;
129+ }
130+
125131 /// <summary>
126132 /// Read all functions and populate function metadata.
127133 /// </summary>
128- internal ImmutableArray < FunctionMetadata > LoadFunctionMetadata ( bool forceRefresh = false , bool includeCustomProviders = true , IFunctionInvocationDispatcher dispatcher = null )
134+ internal ImmutableArray < FunctionMetadata > LoadFunctionMetadata ( bool forceRefresh = false , bool includeCustomProviders = true , IFunctionInvocationDispatcher dispatcher = null , IList < RpcWorkerConfig > workerConfigs = null )
129135 {
136+ workerConfigs ??= GetFallbackWorkerConfig ( ) ;
137+
130138 _functionMetadataMap . Clear ( ) ;
131139
132140 ICollection < string > functionsAllowList = _scriptOptions ? . Value ? . Functions ;
133141 _logger . FunctionMetadataManagerLoadingFunctionsMetadata ( ) ;
134142
135143 ImmutableArray < FunctionMetadata > immutableFunctionMetadata ;
136- var workerConfigs = _languageWorkerOptions . CurrentValue . WorkerConfigs ;
137144
138- immutableFunctionMetadata = _functionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , SystemEnvironment . Instance , forceRefresh ) . GetAwaiter ( ) . GetResult ( ) ;
145+ immutableFunctionMetadata = _functionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , _environment , forceRefresh ) . GetAwaiter ( ) . GetResult ( ) ;
139146
140147 var functionMetadataList = new List < FunctionMetadata > ( ) ;
141148 _functionErrors = new Dictionary < string , ICollection < string > > ( ) ;
0 commit comments