|
18 | 18 | using Microsoft.Azure.WebJobs.Script.ManagedDependencies;
|
19 | 19 | using Microsoft.Extensions.Logging;
|
20 | 20 | using Microsoft.Extensions.Options;
|
21 |
| - |
22 | 21 | using FunctionMetadata = Microsoft.Azure.WebJobs.Script.Description.FunctionMetadata;
|
23 | 22 |
|
24 | 23 | namespace Microsoft.Azure.WebJobs.Script.Workers.Rpc
|
@@ -196,7 +195,7 @@ private void SetDispatcherStateToInitialized(IDictionary<string, TaskCompletionS
|
196 | 195 | // RanToCompletion indicates successful process startup
|
197 | 196 | if (State != FunctionInvocationDispatcherState.Initialized
|
198 | 197 | && webhostLanguageWorkerChannel != null
|
199 |
| - && webhostLanguageWorkerChannel.Where(a => a.Value.Task.Status == TaskStatus.RanToCompletion).Any()) |
| 198 | + && webhostLanguageWorkerChannel.Any(a => a.Value.Task.Status == TaskStatus.RanToCompletion)) |
200 | 199 | {
|
201 | 200 | SetFunctionDispatcherStateToInitializedAndLog();
|
202 | 201 | }
|
@@ -253,7 +252,7 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
|
253 | 252 | return;
|
254 | 253 | }
|
255 | 254 |
|
256 |
| - _workerRuntime = _workerRuntime ?? Utility.GetWorkerRuntime(functions, _environment); |
| 255 | + _workerRuntime ??= Utility.GetWorkerRuntime(functions, _environment); |
257 | 256 |
|
258 | 257 | // In case of multi language runtime, _workerRuntime has no significance, thus skipping this check for multi language runtime environment
|
259 | 258 | if ((string.IsNullOrEmpty(_workerRuntime) || _workerRuntime.Equals(RpcWorkerConstants.DotNetLanguageWorkerName, StringComparison.InvariantCultureIgnoreCase)) && !_environment.IsMultiLanguageRuntimeEnvironment())
|
@@ -294,7 +293,7 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
|
294 | 293 | return;
|
295 | 294 | }
|
296 | 295 |
|
297 |
| - _functions = functions ?? new List<FunctionMetadata>(); |
| 296 | + _functions = functions; |
298 | 297 |
|
299 | 298 | if (_environment.IsMultiLanguageRuntimeEnvironment())
|
300 | 299 | {
|
@@ -351,6 +350,7 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
|
351 | 350 | }
|
352 | 351 | }
|
353 | 352 | }
|
| 353 | + |
354 | 354 | AddLogUserCategory(functions);
|
355 | 355 | }
|
356 | 356 |
|
@@ -402,10 +402,15 @@ public async Task InvokeAsync(ScriptInvocationContext invocationContext)
|
402 | 402 | // This could throw if no initialized workers are found. Shut down instance and retry.
|
403 | 403 | IEnumerable<IRpcWorkerChannel> workerChannels = await GetInitializedWorkerChannelsAsync(invocationContext.FunctionMetadata.Language ?? _workerRuntime);
|
404 | 404 | var rpcWorkerChannel = _functionDispatcherLoadBalancer.GetLanguageWorkerChannel(workerChannels);
|
405 |
| - if (rpcWorkerChannel.FunctionInputBuffers.TryGetValue(invocationContext.FunctionMetadata.GetFunctionId(), out BufferBlock<ScriptInvocationContext> bufferBlock)) |
| 405 | + string functionId = invocationContext.FunctionMetadata.GetFunctionId(); |
| 406 | + if (rpcWorkerChannel.FunctionInputBuffers.TryGetValue(functionId, out BufferBlock<ScriptInvocationContext> bufferBlock)) |
406 | 407 | {
|
407 |
| - _logger.LogTrace("Posting invocation id:{InvocationId} on workerId:{workerChannelId}", invocationContext.ExecutionContext.InvocationId, rpcWorkerChannel.Id); |
408 |
| - rpcWorkerChannel.FunctionInputBuffers[invocationContext.FunctionMetadata.GetFunctionId()].Post(invocationContext); |
| 408 | + if (_logger.IsEnabled(LogLevel.Trace)) |
| 409 | + { |
| 410 | + _logger.LogTrace("Posting invocation id:{InvocationId} on workerId:{workerChannelId}", invocationContext.ExecutionContext.InvocationId, rpcWorkerChannel.Id); |
| 411 | + } |
| 412 | + |
| 413 | + bufferBlock.Post(invocationContext); |
409 | 414 | }
|
410 | 415 | else
|
411 | 416 | {
|
@@ -539,11 +544,12 @@ private async Task DisposeAndRestartWorkerChannel(string runtime, string workerI
|
539 | 544 | if (ShouldRestartWorkerChannel(runtime, isWebHostChannelDisposed, isJobHostChannelDisposed))
|
540 | 545 | {
|
541 | 546 | // Set state to "WorkerProcessRestarting" if there are no other workers to handle work
|
542 |
| - if ((await GetInitializedWorkerChannelsAsync()).Count() == 0) |
| 547 | + if (!(await GetInitializedWorkerChannelsAsync()).Any()) |
543 | 548 | {
|
544 | 549 | State = FunctionInvocationDispatcherState.WorkerProcessRestarting;
|
545 | 550 | _logger.LogDebug("No initialized worker channels for runtime '{runtime}'. Delaying future invocations", runtime);
|
546 | 551 | }
|
| 552 | + |
547 | 553 | // Restart worker channel
|
548 | 554 | _logger.LogDebug("Restarting worker channel for runtime: '{runtime}'", runtime);
|
549 | 555 | await StartWorkerChannel(runtime);
|
|
0 commit comments