@@ -29,29 +29,32 @@ internal class RpcWorkerConfigFactory
29
29
private Dictionary < string , RpcWorkerConfig > _workerDescriptionDictionary = new Dictionary < string , RpcWorkerConfig > ( ) ;
30
30
31
31
public RpcWorkerConfigFactory ( IConfiguration config ,
32
- ILogger logger ,
33
- ISystemRuntimeInformation systemRuntimeInfo ,
34
- IEnvironment environment ,
35
- IMetricsLogger metricsLogger )
32
+ ILogger logger ,
33
+ ISystemRuntimeInformation systemRuntimeInfo ,
34
+ IEnvironment environment ,
35
+ IMetricsLogger metricsLogger )
36
36
{
37
37
_config = config ?? throw new ArgumentNullException ( nameof ( config ) ) ;
38
38
_logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
39
39
_systemRuntimeInformation = systemRuntimeInfo ?? throw new ArgumentNullException ( nameof ( systemRuntimeInfo ) ) ;
40
40
_environment = environment ?? throw new ArgumentNullException ( nameof ( environment ) ) ;
41
41
_metricsLogger = metricsLogger ;
42
42
_workerRuntime = _environment . GetEnvironmentVariable ( RpcWorkerConstants . FunctionWorkerRuntimeSettingName ) ;
43
- string assemblyLocalPath = Path . GetDirectoryName ( new Uri ( typeof ( RpcWorkerConfigFactory ) . Assembly . CodeBase ) . LocalPath ) ;
43
+
44
+ var conditionProviders = new List < IWorkerProfileConditionProvider >
45
+ {
46
+ new WorkerProfileConditionProvider ( _logger , _environment )
47
+ } ;
48
+
49
+ _profileManager = new WorkerProfileManager ( _logger , conditionProviders ) ;
50
+
44
51
WorkersDirPath = GetDefaultWorkersDirectory ( Directory . Exists ) ;
45
52
var workersDirectorySection = _config . GetSection ( $ "{ RpcWorkerConstants . LanguageWorkersSectionName } :{ WorkerConstants . WorkersDirectorySectionName } ") ;
53
+
46
54
if ( ! string . IsNullOrEmpty ( workersDirectorySection . Value ) )
47
55
{
48
56
WorkersDirPath = workersDirectorySection . Value ;
49
57
}
50
- var conditionProviders = new List < IWorkerProfileConditionProvider >
51
- {
52
- new WorkerProfileConditionProvider ( _logger , _environment )
53
- } ;
54
- _profileManager = new WorkerProfileManager ( _logger , conditionProviders ) ;
55
58
}
56
59
57
60
public string WorkersDirPath { get ; }
@@ -85,7 +88,7 @@ internal void BuildWorkerProviderDictionary()
85
88
86
89
internal void AddProviders ( )
87
90
{
88
- _logger . LogDebug ( $ "Workers Directory set to: { WorkersDirPath } ") ;
91
+ _logger . LogDebug ( "Workers Directory set to: {WorkersDirPath}" , WorkersDirPath ) ;
89
92
90
93
foreach ( var workerDir in Directory . EnumerateDirectories ( WorkersDirPath ) )
91
94
{
@@ -118,13 +121,16 @@ internal void AddProvider(string workerDir)
118
121
try
119
122
{
120
123
string workerConfigPath = Path . Combine ( workerDir , RpcWorkerConstants . WorkerConfigFileName ) ;
124
+
121
125
if ( ! File . Exists ( workerConfigPath ) )
122
126
{
123
- _logger . LogDebug ( $ "Did not find worker config file at: { workerConfigPath } ") ;
127
+ _logger . LogDebug ( "Did not find worker config file at: {workerConfigPath}" , workerConfigPath ) ;
124
128
return ;
125
129
}
130
+
131
+ _logger . LogDebug ( "Found worker config: {workerConfigPath}" , workerConfigPath ) ;
132
+
126
133
// Parse worker config file
127
- _logger . LogDebug ( $ "Found worker config: { workerConfigPath } ") ;
128
134
string json = File . ReadAllText ( workerConfigPath ) ;
129
135
JObject workerConfig = JObject . Parse ( json ) ;
130
136
RpcWorkerDescription workerDescription = workerConfig . Property ( WorkerConstants . WorkerDescription ) . Value . ToObject < RpcWorkerDescription > ( ) ;
@@ -142,7 +148,7 @@ internal void AddProvider(string workerDir)
142
148
}
143
149
}
144
150
145
- // Check if any appsettings are provided for that langauge
151
+ // Check if any app settings are provided for that language
146
152
var languageSection = _config . GetSection ( $ "{ RpcWorkerConstants . LanguageWorkersSectionName } :{ workerDescription . Language } ") ;
147
153
workerDescription . Arguments = workerDescription . Arguments ?? new List < string > ( ) ;
148
154
GetWorkerDescriptionFromAppSettings ( workerDescription , languageSection ) ;
@@ -165,21 +171,25 @@ internal void AddProvider(string workerDir)
165
171
ExecutablePath = workerDescription . DefaultExecutablePath ,
166
172
WorkerPath = workerDescription . DefaultWorkerPath
167
173
} ;
174
+
168
175
arguments . ExecutableArguments . AddRange ( workerDescription . Arguments ) ;
176
+
169
177
var rpcWorkerConfig = new RpcWorkerConfig ( )
170
178
{
171
179
Description = workerDescription ,
172
180
Arguments = arguments ,
173
181
CountOptions = workerProcessCount ,
174
182
} ;
183
+
175
184
_workerDescriptionDictionary [ workerDescription . Language ] = rpcWorkerConfig ;
176
185
ReadLanguageWorkerFile ( arguments . WorkerPath ) ;
177
- _logger . LogDebug ( $ "Added WorkerConfig for language: { workerDescription . Language } ") ;
186
+
187
+ _logger . LogDebug ( "Added WorkerConfig for language: {language}" , workerDescription . Language ) ;
178
188
}
179
189
}
180
- catch ( Exception ex )
190
+ catch ( Exception ex ) when ( ! ex . IsFatal ( ) )
181
191
{
182
- _logger ? . LogError ( ex , $ "Failed to initialize worker provider for: { workerDir } ") ;
192
+ _logger . LogError ( ex , "Failed to initialize worker provider for: {workerDir}" , workerDir ) ;
183
193
}
184
194
}
185
195
}
@@ -194,6 +204,7 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
194
204
}
195
205
196
206
var descriptionProfiles = new List < WorkerDescriptionProfile > ( profiles . Count ) ;
207
+
197
208
try
198
209
{
199
210
foreach ( var profile in profiles )
@@ -205,7 +216,7 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
205
216
if ( ! _profileManager . TryCreateWorkerProfileCondition ( descriptor , out IWorkerProfileCondition condition ) )
206
217
{
207
218
// Failed to resolve condition. This profile will be disabled using a mock false condition
208
- _logger ? . LogInformation ( $ "Profile { profile . ProfileName } is disabled. Cannot resolve the profile condition { descriptor . Type } " ) ;
219
+ _logger . LogInformation ( "Profile {name } is disabled. Cannot resolve the profile condition {condition}" , profile . ProfileName , descriptor . Type ) ;
209
220
condition = new FalseCondition ( ) ;
210
221
}
211
222
@@ -219,6 +230,7 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
219
230
{
220
231
throw new FormatException ( "Failed to parse profiles in worker config." ) ;
221
232
}
233
+
222
234
return descriptionProfiles ;
223
235
}
224
236
@@ -286,31 +298,33 @@ internal bool ShouldAddWorkerConfig(string workerDescriptionLanguage)
286
298
287
299
if ( _environment . IsMultiLanguageRuntimeEnvironment ( ) )
288
300
{
289
- _logger . LogInformation ( $ "Found multi-language runtime environment. Starting WorkerConfig for language: { workerDescriptionLanguage } ") ;
301
+ _logger . LogInformation ( "Found multi-language runtime environment. Starting WorkerConfig for language: {workerDescriptionLanguage}" , workerDescriptionLanguage ) ;
290
302
return true ;
291
303
}
292
304
293
305
if ( ! string . IsNullOrEmpty ( _workerRuntime ) )
294
306
{
295
- _logger . LogDebug ( $ "EnvironmentVariable { RpcWorkerConstants . FunctionWorkerRuntimeSettingName } : { _workerRuntime } " ) ;
307
+ _logger . LogDebug ( "EnvironmentVariable {functionWorkerRuntimeSettingName }: {workerRuntime}" , RpcWorkerConstants . FunctionWorkerRuntimeSettingName , _workerRuntime ) ;
296
308
if ( _workerRuntime . Equals ( workerDescriptionLanguage , StringComparison . OrdinalIgnoreCase ) )
297
309
{
298
310
return true ;
299
311
}
312
+
300
313
// After specialization only create worker provider for the language set by FUNCTIONS_WORKER_RUNTIME env variable
301
- _logger . LogInformation ( $ " { RpcWorkerConstants . FunctionWorkerRuntimeSettingName } set to { _workerRuntime } . Skipping WorkerConfig for language:{ workerDescriptionLanguage } ") ;
314
+ _logger . LogInformation ( "{FUNCTIONS_WORKER_RUNTIME } set to {workerRuntime }. Skipping WorkerConfig for language: {workerDescriptionLanguage}", RpcWorkerConstants . FunctionWorkerRuntimeSettingName , _workerRuntime , workerDescriptionLanguage ) ;
302
315
return false ;
303
316
}
317
+
304
318
return true ;
305
319
}
306
320
307
- internal void ReadLanguageWorkerFile ( string workerPath )
321
+ private void ReadLanguageWorkerFile ( string workerPath )
308
322
{
309
- if ( _environment . IsPlaceholderModeEnabled ( ) &&
310
- ! string . IsNullOrEmpty ( _workerRuntime ) &&
311
- File . Exists ( workerPath ) )
323
+ if ( _environment . IsPlaceholderModeEnabled ( )
324
+ && ! string . IsNullOrEmpty ( _workerRuntime )
325
+ && File . Exists ( workerPath ) )
312
326
{
313
- // Read lanaguage worker file to avoid disk reads during specialization. This is only to page-in bytes.
327
+ // Read language worker file to avoid disk reads during specialization. This is only to page-in bytes.
314
328
File . ReadAllBytes ( workerPath ) ;
315
329
}
316
330
}
0 commit comments