@@ -297,7 +297,7 @@ public async Task<WorkerStatus> GetWorkerStatusAsync()
297
297
await tcs . Task ;
298
298
var elapsed = sw . GetElapsedTime ( ) ;
299
299
workerStatus . Latency = elapsed ;
300
- _workerChannelLogger . LogDebug ( $ "[HostMonitor] Worker status request took { elapsed . TotalMilliseconds } ms") ;
300
+ _workerChannelLogger . LogDebug ( "[HostMonitor] Worker status request took {totalMs }ms" , elapsed . TotalMilliseconds ) ;
301
301
}
302
302
}
303
303
@@ -373,14 +373,14 @@ internal void WorkerInitResponse(GrpcEvent initEvent)
373
373
374
374
_workerChannelLogger . LogDebug ( "Received WorkerInitResponse. Worker process initialized" ) ;
375
375
_initMessage = initEvent . Message . WorkerInitResponse ;
376
- _workerChannelLogger . LogDebug ( $ "Worker capabilities: { _initMessage . Capabilities } " ) ;
376
+ _workerChannelLogger . LogDebug ( "Worker capabilities: {capabilities}" , _initMessage . Capabilities ) ;
377
377
378
378
if ( _initMessage . WorkerMetadata != null )
379
379
{
380
380
_initMessage . UpdateWorkerMetadata ( _workerConfig ) ;
381
381
var workerMetadata = _initMessage . WorkerMetadata . ToString ( ) ;
382
382
_metricsLogger . LogEvent ( MetricEventNames . WorkerMetadata , functionName : null , workerMetadata ) ;
383
- _workerChannelLogger . LogDebug ( $ "Worker metadata: { workerMetadata } ") ;
383
+ _workerChannelLogger . LogDebug ( "Worker metadata: {workerMetadata}" , workerMetadata ) ;
384
384
}
385
385
386
386
if ( _initMessage . Result . IsFailure ( out Exception exc ) )
@@ -472,7 +472,7 @@ internal void SendFunctionLoadRequestCollection(IEnumerable<FunctionMetadata> fu
472
472
473
473
FunctionLoadRequestCollection functionLoadRequestCollection = GetFunctionLoadRequestCollection ( functions , managedDependencyOptions ) ;
474
474
475
- _workerChannelLogger . LogDebug ( "Sending FunctionLoadRequestCollection with number of functions:'{count}'" , functionLoadRequestCollection . FunctionLoadRequests . Count ) ;
475
+ _workerChannelLogger . LogDebug ( "Sending FunctionLoadRequestCollection with number of functions: '{count}'" , functionLoadRequestCollection . FunctionLoadRequests . Count ) ;
476
476
477
477
// send load requests for the registered functions
478
478
SendStreamingMessage ( new StreamingMessage
@@ -540,7 +540,7 @@ internal FunctionEnvironmentReloadRequest GetFunctionEnvironmentReloadRequest(ID
540
540
internal void SendFunctionLoadRequest ( FunctionMetadata metadata , ManagedDependencyOptions managedDependencyOptions )
541
541
{
542
542
_functionLoadRequestResponseEvent = _metricsLogger . LatencyEvent ( MetricEventNames . FunctionLoadRequestResponse ) ;
543
- _workerChannelLogger . LogDebug ( "Sending FunctionLoadRequest for function:'{functionName}' with functionId:'{functionId}'" , metadata . Name , metadata . GetFunctionId ( ) ) ;
543
+ _workerChannelLogger . LogDebug ( "Sending FunctionLoadRequest for function: '{functionName}' with functionId: '{functionId}'" , metadata . Name , metadata . GetFunctionId ( ) ) ;
544
544
545
545
// send a load request for the registered function
546
546
SendStreamingMessage ( new StreamingMessage
@@ -566,7 +566,7 @@ internal FunctionLoadRequest GetFunctionLoadRequest(FunctionMetadata metadata, M
566
566
567
567
if ( managedDependencyOptions != null && managedDependencyOptions . Enabled )
568
568
{
569
- _workerChannelLogger ? . LogDebug ( $ "Adding dependency download request to { _workerConfig . Description . Language } language worker") ;
569
+ _workerChannelLogger ? . LogDebug ( "Adding dependency download request to {language } language worker" , _workerConfig . Description . Language ) ;
570
570
request . ManagedDependencyEnabled = managedDependencyOptions . Enabled ;
571
571
}
572
572
@@ -595,19 +595,19 @@ internal void LoadResponse(FunctionLoadResponse loadResponse)
595
595
{
596
596
if ( functionLoadEx == null )
597
597
{
598
- _workerChannelLogger ? . LogError ( "Worker failed to to load function: '{functionName}' with function id : '{functionId}'. Function load exception is not set by the worker." , functionName , loadResponse . FunctionId ) ;
598
+ _workerChannelLogger ? . LogError ( "Worker failed to to load function: '{functionName}' with functionId : '{functionId}'. Function load exception is not set by the worker." , functionName , loadResponse . FunctionId ) ;
599
599
}
600
600
else
601
601
{
602
- _workerChannelLogger ? . LogError ( functionLoadEx , "Worker failed to load function: '{functionName}' with function id : '{functionId}'." , functionName , loadResponse . FunctionId ) ;
602
+ _workerChannelLogger ? . LogError ( functionLoadEx , "Worker failed to load function: '{functionName}' with functionId : '{functionId}'." , functionName , loadResponse . FunctionId ) ;
603
603
}
604
604
//Cache function load errors to replay error messages on invoking failed functions
605
605
_functionLoadErrors [ loadResponse . FunctionId ] = functionLoadEx ;
606
606
}
607
607
608
608
if ( loadResponse . IsDependencyDownloaded )
609
609
{
610
- _workerChannelLogger ? . LogDebug ( $ "Managed dependency successfully downloaded by the { _workerConfig . Description . Language } language worker") ;
610
+ _workerChannelLogger ? . LogDebug ( "Managed dependency successfully downloaded by the {workerLanguage } language worker" , _workerConfig . Description . Language ) ;
611
611
}
612
612
613
613
// link the invocation inputs to the invoke call
@@ -631,44 +631,47 @@ internal async Task SendInvocationRequest(ScriptInvocationContext context)
631
631
{
632
632
try
633
633
{
634
- // do not send invocation requests for functions that failed to load or could not be indexed by the worker
634
+ var invocationId = context . ExecutionContext . InvocationId . ToString ( ) ;
635
+
636
+ // do not send an invocation request for functions that failed to load or could not be indexed by the worker
635
637
if ( _functionLoadErrors . ContainsKey ( context . FunctionMetadata . GetFunctionId ( ) ) )
636
638
{
637
- _workerChannelLogger . LogDebug ( $ "Function { context . FunctionMetadata . Name } failed to load") ;
639
+ _workerChannelLogger . LogDebug ( "Function {functionName } failed to load" , context . FunctionMetadata . Name ) ;
638
640
context . ResultSource . TrySetException ( _functionLoadErrors [ context . FunctionMetadata . GetFunctionId ( ) ] ) ;
639
- _executingInvocations . TryRemove ( context . ExecutionContext . InvocationId . ToString ( ) , out ScriptInvocationContext _ ) ;
641
+ _executingInvocations . TryRemove ( invocationId , out ScriptInvocationContext _ ) ;
640
642
return ;
641
643
}
642
644
else if ( _metadataRequestErrors . ContainsKey ( context . FunctionMetadata . GetFunctionId ( ) ) )
643
645
{
644
- _workerChannelLogger . LogDebug ( $ "Worker failed to load metadata for { context . FunctionMetadata . Name } " ) ;
646
+ _workerChannelLogger . LogDebug ( "Worker failed to load metadata for {functionName}" , context . FunctionMetadata . Name ) ;
645
647
context . ResultSource . TrySetException ( _metadataRequestErrors [ context . FunctionMetadata . GetFunctionId ( ) ] ) ;
646
- _executingInvocations . TryRemove ( context . ExecutionContext . InvocationId . ToString ( ) , out ScriptInvocationContext _ ) ;
648
+ _executingInvocations . TryRemove ( invocationId , out ScriptInvocationContext _ ) ;
647
649
return ;
648
650
}
649
651
652
+ // do not send an invocation request if cancellation has been requested
650
653
if ( context . CancellationToken . IsCancellationRequested )
651
654
{
652
- _workerChannelLogger . LogDebug ( "Cancellation has been requested, cancelling invocation request" ) ;
653
- context . ResultSource . SetCanceled ( ) ;
655
+ _workerChannelLogger . LogWarning ( "Cancellation has been requested. The invocation request with id '{invocationId}' is cancelled and will not be sent to the worker." , invocationId ) ;
656
+ context . ResultSource . TrySetCanceled ( ) ;
654
657
return ;
655
658
}
656
659
657
660
var invocationRequest = await context . ToRpcInvocationRequest ( _workerChannelLogger , _workerCapabilities , _isSharedMemoryDataTransferEnabled , _sharedMemoryManager ) ;
658
661
AddAdditionalTraceContext ( invocationRequest . TraceContext . Attributes , context ) ;
659
662
_executingInvocations . TryAdd ( invocationRequest . InvocationId , context ) ;
660
663
661
- if ( _cancelCapabilityEnabled )
662
- {
663
- context . CancellationToken . Register ( ( ) => SendInvocationCancel ( invocationRequest . InvocationId ) ) ;
664
- }
665
-
666
664
_metricsLogger . LogEvent ( string . Format ( MetricEventNames . WorkerInvoked , Id ) , functionName : context . FunctionMetadata . Name ) ;
667
665
668
666
await SendStreamingMessageAsync ( new StreamingMessage
669
667
{
670
668
InvocationRequest = invocationRequest
671
669
} ) ;
670
+
671
+ if ( _cancelCapabilityEnabled )
672
+ {
673
+ context . CancellationToken . Register ( ( ) => SendInvocationCancel ( invocationRequest . InvocationId ) ) ;
674
+ }
672
675
}
673
676
catch ( Exception invokeEx )
674
677
{
@@ -678,7 +681,7 @@ await SendStreamingMessageAsync(new StreamingMessage
678
681
679
682
internal void SendInvocationCancel ( string invocationId )
680
683
{
681
- _workerChannelLogger . LogDebug ( $ "Sending invocation cancel request for InvocationId { invocationId } " ) ;
684
+ _workerChannelLogger . LogDebug ( "Sending InvocationCancel request for invocation: ' {invocationId}'" , invocationId ) ;
682
685
683
686
var invocationCancel = new InvocationCancel
684
687
{
@@ -740,7 +743,7 @@ internal void ProcessFunctionMetadataResponses(FunctionMetadataResponse function
740
743
}
741
744
if ( metadata . Status != null && metadata . Status . IsFailure ( out Exception metadataRequestEx ) )
742
745
{
743
- _workerChannelLogger . LogError ( $ "Worker failed to index function { metadata . FunctionId } " ) ;
746
+ _workerChannelLogger . LogError ( "Worker failed to index function {functionId}" , metadata . FunctionId ) ;
744
747
_metadataRequestErrors [ metadata . FunctionId ] = metadataRequestEx ;
745
748
}
746
749
@@ -824,7 +827,8 @@ private IList<string> GetOutputMaps(IList<ParameterBinding> bindings)
824
827
825
828
internal async Task InvokeResponse ( InvocationResponse invokeResponse )
826
829
{
827
- _workerChannelLogger . LogDebug ( "InvocationResponse received for invocation id: '{invocationId}'" , invokeResponse . InvocationId ) ;
830
+ _workerChannelLogger . LogDebug ( "InvocationResponse received for invocation: '{invocationId}'" , invokeResponse . InvocationId ) ;
831
+
828
832
// Check if the worker supports logging user-code-thrown exceptions to app insights
829
833
bool capabilityEnabled = ! string . IsNullOrEmpty ( _workerCapabilities . GetCapabilityState ( RpcWorkerConstants . EnableUserCodeException ) ) ;
830
834
@@ -854,7 +858,7 @@ internal async Task InvokeResponse(InvocationResponse invokeResponse)
854
858
855
859
if ( usedSharedMemory )
856
860
{
857
- _workerChannelLogger . LogDebug ( "Shared memory usage for response of invocation Id: {Id} is {SharedMemoryUsage}" , invokeResponse . InvocationId , logBuilder . ToString ( ) ) ;
861
+ _workerChannelLogger . LogDebug ( "Shared memory usage for response of invocation '{invocationId}' is {SharedMemoryUsage}" , invokeResponse . InvocationId , logBuilder . ToString ( ) ) ;
858
862
}
859
863
860
864
IDictionary < string , object > bindingsDictionary = await invokeResponse . OutputData
@@ -876,7 +880,7 @@ internal async Task InvokeResponse(InvocationResponse invokeResponse)
876
880
// Free memory allocated by the host (for input bindings) which was needed only for the duration of this invocation
877
881
if ( ! _sharedMemoryManager . TryFreeSharedMemoryMapsForInvocation ( invokeResponse . InvocationId ) )
878
882
{
879
- _workerChannelLogger . LogWarning ( $ "Cannot free all shared memory resources for invocation: { invokeResponse . InvocationId } " ) ;
883
+ _workerChannelLogger . LogWarning ( "Cannot free all shared memory resources for invocation: {invocationId}" , invokeResponse . InvocationId ) ;
880
884
}
881
885
882
886
// List of shared memory maps that were produced by the worker (for output bindings)
@@ -1152,7 +1156,7 @@ private void StopWorkerProcess()
1152
1156
GracePeriod = Duration . FromTimeSpan ( TimeSpan . FromSeconds ( gracePeriod ) )
1153
1157
} ;
1154
1158
1155
- _workerChannelLogger . LogDebug ( $ "Sending WorkerTerminate message with grace period { gracePeriod } seconds.") ;
1159
+ _workerChannelLogger . LogDebug ( "Sending WorkerTerminate message with grace period of {gracePeriod} seconds." , gracePeriod ) ;
1156
1160
1157
1161
SendStreamingMessage ( new StreamingMessage
1158
1162
{
@@ -1164,7 +1168,7 @@ private void StopWorkerProcess()
1164
1168
1165
1169
public async Task DrainInvocationsAsync ( )
1166
1170
{
1167
- _workerChannelLogger . LogDebug ( $ "Count of in-buffer invocations waiting to be drained out: { _executingInvocations . Count } " ) ;
1171
+ _workerChannelLogger . LogDebug ( "Count of in-buffer invocations waiting to be drained out: {invocationCount}" , _executingInvocations . Count ) ;
1168
1172
foreach ( ScriptInvocationContext currContext in _executingInvocations . Values )
1169
1173
{
1170
1174
await currContext . ResultSource . Task ;
@@ -1186,7 +1190,7 @@ public bool TryFailExecutions(Exception workerException)
1186
1190
foreach ( ScriptInvocationContext currContext in _executingInvocations ? . Values )
1187
1191
{
1188
1192
string invocationId = currContext ? . ExecutionContext ? . InvocationId . ToString ( ) ;
1189
- _workerChannelLogger . LogDebug ( "Worker '{workerId}' encountered a fatal error. Failing invocation id : '{invocationId}'" , _workerId , invocationId ) ;
1193
+ _workerChannelLogger . LogDebug ( "Worker '{workerId}' encountered a fatal error. Failing invocation: '{invocationId}'" , _workerId , invocationId ) ;
1190
1194
currContext ? . ResultSource ? . TrySetException ( workerException ) ;
1191
1195
_executingInvocations . TryRemove ( invocationId , out ScriptInvocationContext _ ) ;
1192
1196
}
0 commit comments