@@ -30,17 +30,15 @@ public class FunctionMetadataManager : IFunctionMetadataManager
30
30
private bool _servicesReset = false ;
31
31
private ILogger _logger ;
32
32
private IOptions < ScriptJobHostOptions > _scriptOptions ;
33
- private IOptionsMonitor < LanguageWorkerOptions > _languageWorkerOptions ;
34
33
private ImmutableArray < FunctionMetadata > _functionMetadataArray ;
35
34
private Dictionary < string , ICollection < string > > _functionErrors = new Dictionary < string , ICollection < string > > ( ) ;
36
35
private ConcurrentDictionary < string , FunctionMetadata > _functionMetadataMap = new ConcurrentDictionary < string , FunctionMetadata > ( StringComparer . OrdinalIgnoreCase ) ;
37
36
38
37
public FunctionMetadataManager ( IOptions < ScriptJobHostOptions > scriptOptions , IFunctionMetadataProvider functionMetadataProvider ,
39
38
IOptions < HttpWorkerOptions > httpWorkerOptions , IScriptHostManager scriptHostManager , ILoggerFactory loggerFactory ,
40
- IOptionsMonitor < LanguageWorkerOptions > languageWorkerOptions , IEnvironment environment )
39
+ IEnvironment environment )
41
40
{
42
41
_scriptOptions = scriptOptions ;
43
- _languageWorkerOptions = languageWorkerOptions ;
44
42
_serviceProvider = scriptHostManager as IServiceProvider ;
45
43
_functionMetadataProvider = functionMetadataProvider ;
46
44
_loggerFactory = loggerFactory ;
@@ -84,11 +82,11 @@ public bool TryGetFunctionMetadata(string functionName, out FunctionMetadata fun
84
82
/// <param name="applyAllowList">Apply functions allow list filter.</param>
85
83
/// <param name="includeCustomProviders">Include any metadata provided by IFunctionProvider when loading the metadata</param>
86
84
/// <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 )
88
86
{
89
87
if ( forceRefresh || _servicesReset || _functionMetadataArray . IsDefaultOrEmpty )
90
88
{
91
- _functionMetadataArray = LoadFunctionMetadata ( forceRefresh , includeCustomProviders ) ;
89
+ _functionMetadataArray = LoadFunctionMetadata ( forceRefresh , includeCustomProviders , workerConfigs : workerConfigs ) ;
92
90
_logger . FunctionMetadataManagerFunctionsLoaded ( ApplyAllowList ( _functionMetadataArray ) . Count ( ) ) ;
93
91
_servicesReset = false ;
94
92
}
@@ -114,28 +112,37 @@ private void InitializeServices()
114
112
115
113
_isHttpWorker = _serviceProvider . GetService < IOptions < HttpWorkerOptions > > ( ) ? . Value ? . Description != null ;
116
114
_scriptOptions = _serviceProvider . GetService < IOptions < ScriptJobHostOptions > > ( ) ;
117
- _languageWorkerOptions = _serviceProvider . GetService < IOptionsMonitor < LanguageWorkerOptions > > ( ) ;
118
115
119
116
// Resetting the logger switches the logger scope to Script Host level,
120
117
// also making the logs available to Application Insights
121
118
_logger = _serviceProvider ? . GetService < ILoggerFactory > ( ) . CreateLogger ( LogCategories . Startup ) ;
122
119
_servicesReset = true ;
123
120
}
124
121
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
+
125
131
/// <summary>
126
132
/// Read all functions and populate function metadata.
127
133
/// </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 )
129
135
{
136
+ workerConfigs ??= GetFallbackWorkerConfig ( ) ;
137
+
130
138
_functionMetadataMap . Clear ( ) ;
131
139
132
140
ICollection < string > functionsAllowList = _scriptOptions ? . Value ? . Functions ;
133
141
_logger . FunctionMetadataManagerLoadingFunctionsMetadata ( ) ;
134
142
135
143
ImmutableArray < FunctionMetadata > immutableFunctionMetadata ;
136
- var workerConfigs = _languageWorkerOptions . CurrentValue . WorkerConfigs ;
137
144
138
- immutableFunctionMetadata = _functionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , SystemEnvironment . Instance , forceRefresh ) . GetAwaiter ( ) . GetResult ( ) ;
145
+ immutableFunctionMetadata = _functionMetadataProvider . GetFunctionMetadataAsync ( workerConfigs , _environment , forceRefresh ) . GetAwaiter ( ) . GetResult ( ) ;
139
146
140
147
var functionMetadataList = new List < FunctionMetadata > ( ) ;
141
148
_functionErrors = new Dictionary < string , ICollection < string > > ( ) ;
0 commit comments