@@ -29,29 +29,32 @@ internal class RpcWorkerConfigFactory
2929 private Dictionary < string , RpcWorkerConfig > _workerDescriptionDictionary = new Dictionary < string , RpcWorkerConfig > ( ) ;
3030
3131 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 )
3636 {
3737 _config = config ?? throw new ArgumentNullException ( nameof ( config ) ) ;
3838 _logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
3939 _systemRuntimeInformation = systemRuntimeInfo ?? throw new ArgumentNullException ( nameof ( systemRuntimeInfo ) ) ;
4040 _environment = environment ?? throw new ArgumentNullException ( nameof ( environment ) ) ;
4141 _metricsLogger = metricsLogger ;
4242 _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+
4451 WorkersDirPath = GetDefaultWorkersDirectory ( Directory . Exists ) ;
4552 var workersDirectorySection = _config . GetSection ( $ "{ RpcWorkerConstants . LanguageWorkersSectionName } :{ WorkerConstants . WorkersDirectorySectionName } ") ;
53+
4654 if ( ! string . IsNullOrEmpty ( workersDirectorySection . Value ) )
4755 {
4856 WorkersDirPath = workersDirectorySection . Value ;
4957 }
50- var conditionProviders = new List < IWorkerProfileConditionProvider >
51- {
52- new WorkerProfileConditionProvider ( _logger , _environment )
53- } ;
54- _profileManager = new WorkerProfileManager ( _logger , conditionProviders ) ;
5558 }
5659
5760 public string WorkersDirPath { get ; }
@@ -85,7 +88,7 @@ internal void BuildWorkerProviderDictionary()
8588
8689 internal void AddProviders ( )
8790 {
88- _logger . LogDebug ( $ "Workers Directory set to: { WorkersDirPath } ") ;
91+ _logger . LogDebug ( "Workers Directory set to: {WorkersDirPath}" , WorkersDirPath ) ;
8992
9093 foreach ( var workerDir in Directory . EnumerateDirectories ( WorkersDirPath ) )
9194 {
@@ -118,13 +121,16 @@ internal void AddProvider(string workerDir)
118121 try
119122 {
120123 string workerConfigPath = Path . Combine ( workerDir , RpcWorkerConstants . WorkerConfigFileName ) ;
124+
121125 if ( ! File . Exists ( workerConfigPath ) )
122126 {
123- _logger . LogDebug ( $ "Did not find worker config file at: { workerConfigPath } ") ;
127+ _logger . LogDebug ( "Did not find worker config file at: {workerConfigPath}" , workerConfigPath ) ;
124128 return ;
125129 }
130+
131+ _logger . LogDebug ( "Found worker config: {workerConfigPath}" , workerConfigPath ) ;
132+
126133 // Parse worker config file
127- _logger . LogDebug ( $ "Found worker config: { workerConfigPath } ") ;
128134 string json = File . ReadAllText ( workerConfigPath ) ;
129135 JObject workerConfig = JObject . Parse ( json ) ;
130136 RpcWorkerDescription workerDescription = workerConfig . Property ( WorkerConstants . WorkerDescription ) . Value . ToObject < RpcWorkerDescription > ( ) ;
@@ -142,7 +148,7 @@ internal void AddProvider(string workerDir)
142148 }
143149 }
144150
145- // Check if any appsettings are provided for that langauge
151+ // Check if any app settings are provided for that language
146152 var languageSection = _config . GetSection ( $ "{ RpcWorkerConstants . LanguageWorkersSectionName } :{ workerDescription . Language } ") ;
147153 workerDescription . Arguments = workerDescription . Arguments ?? new List < string > ( ) ;
148154 GetWorkerDescriptionFromAppSettings ( workerDescription , languageSection ) ;
@@ -165,21 +171,25 @@ internal void AddProvider(string workerDir)
165171 ExecutablePath = workerDescription . DefaultExecutablePath ,
166172 WorkerPath = workerDescription . DefaultWorkerPath
167173 } ;
174+
168175 arguments . ExecutableArguments . AddRange ( workerDescription . Arguments ) ;
176+
169177 var rpcWorkerConfig = new RpcWorkerConfig ( )
170178 {
171179 Description = workerDescription ,
172180 Arguments = arguments ,
173181 CountOptions = workerProcessCount ,
174182 } ;
183+
175184 _workerDescriptionDictionary [ workerDescription . Language ] = rpcWorkerConfig ;
176185 ReadLanguageWorkerFile ( arguments . WorkerPath ) ;
177- _logger . LogDebug ( $ "Added WorkerConfig for language: { workerDescription . Language } ") ;
186+
187+ _logger . LogDebug ( "Added WorkerConfig for language: {language}" , workerDescription . Language ) ;
178188 }
179189 }
180- catch ( Exception ex )
190+ catch ( Exception ex ) when ( ! ex . IsFatal ( ) )
181191 {
182- _logger ? . LogError ( ex , $ "Failed to initialize worker provider for: { workerDir } ") ;
192+ _logger . LogError ( ex , "Failed to initialize worker provider for: {workerDir}" , workerDir ) ;
183193 }
184194 }
185195 }
@@ -194,6 +204,7 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
194204 }
195205
196206 var descriptionProfiles = new List < WorkerDescriptionProfile > ( profiles . Count ) ;
207+
197208 try
198209 {
199210 foreach ( var profile in profiles )
@@ -205,7 +216,7 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
205216 if ( ! _profileManager . TryCreateWorkerProfileCondition ( descriptor , out IWorkerProfileCondition condition ) )
206217 {
207218 // 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 ) ;
209220 condition = new FalseCondition ( ) ;
210221 }
211222
@@ -219,6 +230,7 @@ private List<WorkerDescriptionProfile> ReadWorkerDescriptionProfiles(JToken prof
219230 {
220231 throw new FormatException ( "Failed to parse profiles in worker config." ) ;
221232 }
233+
222234 return descriptionProfiles ;
223235 }
224236
@@ -286,31 +298,33 @@ internal bool ShouldAddWorkerConfig(string workerDescriptionLanguage)
286298
287299 if ( _environment . IsMultiLanguageRuntimeEnvironment ( ) )
288300 {
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 ) ;
290302 return true ;
291303 }
292304
293305 if ( ! string . IsNullOrEmpty ( _workerRuntime ) )
294306 {
295- _logger . LogDebug ( $ "EnvironmentVariable { RpcWorkerConstants . FunctionWorkerRuntimeSettingName } : { _workerRuntime } " ) ;
307+ _logger . LogDebug ( "EnvironmentVariable {functionWorkerRuntimeSettingName }: {workerRuntime}" , RpcWorkerConstants . FunctionWorkerRuntimeSettingName , _workerRuntime ) ;
296308 if ( _workerRuntime . Equals ( workerDescriptionLanguage , StringComparison . OrdinalIgnoreCase ) )
297309 {
298310 return true ;
299311 }
312+
300313 // 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 ) ;
302315 return false ;
303316 }
317+
304318 return true ;
305319 }
306320
307- internal void ReadLanguageWorkerFile ( string workerPath )
321+ private void ReadLanguageWorkerFile ( string workerPath )
308322 {
309- if ( _environment . IsPlaceholderModeEnabled ( ) &&
310- ! string . IsNullOrEmpty ( _workerRuntime ) &&
311- File . Exists ( workerPath ) )
323+ if ( _environment . IsPlaceholderModeEnabled ( )
324+ && ! string . IsNullOrEmpty ( _workerRuntime )
325+ && File . Exists ( workerPath ) )
312326 {
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.
314328 File . ReadAllBytes ( workerPath ) ;
315329 }
316330 }
0 commit comments