@@ -34,7 +34,7 @@ public Processor(GrpcDurableTaskWorker worker, TaskHubSidecarServiceClient sidec
3434 {
3535 this . worker = worker ;
3636 this . sidecar = sidecar ;
37- this . shimFactory = new DurableTaskShimFactory ( this . worker . options , this . worker . loggerFactory ) ;
37+ this . shimFactory = new DurableTaskShimFactory ( this . worker . grpcOptions , this . worker . loggerFactory ) ;
3838 }
3939
4040 ILogger Logger => this . worker . logger ;
@@ -102,7 +102,7 @@ static OrchestrationRuntimeState BuildRuntimeState(P.OrchestratorRequest request
102102
103103 if ( runtimeState . ExecutionStartedEvent == null )
104104 {
105- // TODO: What's the right way to handle this? Callback to the sidecar with a retryable error request?
105+ // TODO: What's the right way to handle this? Callback to the sidecar with a retriable error request?
106106 throw new InvalidOperationException ( "The provided orchestration history was incomplete" ) ;
107107 }
108108
@@ -133,8 +133,16 @@ static string GetActionsListForLogging(IReadOnlyList<P.OrchestratorAction> actio
133133 await this . sidecar ! . HelloAsync ( EmptyMessage , cancellationToken : cancellation ) ;
134134 this . Logger . EstablishedWorkItemConnection ( ) ;
135135
136+ DurableTaskWorkerOptions workerOptions = this . worker . workerOptions ;
137+
136138 // Get the stream for receiving work-items
137- return this . sidecar ! . GetWorkItems ( new P . GetWorkItemsRequest ( ) , cancellationToken : cancellation ) ;
139+ return this . sidecar ! . GetWorkItems (
140+ new P . GetWorkItemsRequest
141+ {
142+ MaxConcurrentActivityWorkItems = workerOptions . MaximumConcurrentActivityWorkItems ,
143+ MaxConcurrentOrchestrationWorkItems = workerOptions . MaximumConcurrentOrchestrationWorkItems ,
144+ } ,
145+ cancellationToken : cancellation ) ;
138146 }
139147
140148 async Task ProcessWorkItemsAsync ( AsyncServerStreamingCall < P . WorkItem > stream , CancellationToken cancellation )
@@ -145,16 +153,25 @@ async Task ProcessWorkItemsAsync(AsyncServerStreamingCall<P.WorkItem> stream, Ca
145153 {
146154 if ( workItem . RequestCase == P . WorkItem . RequestOneofCase . OrchestratorRequest )
147155 {
148- this . RunBackgroundTask ( workItem , ( ) => this . OnRunOrchestratorAsync (
149- workItem . OrchestratorRequest ) ) ;
156+ this . RunBackgroundTask (
157+ workItem ,
158+ ( ) => this . OnRunOrchestratorAsync ( workItem . OrchestratorRequest , workItem . CompletionToken ) ) ;
150159 }
151160 else if ( workItem . RequestCase == P . WorkItem . RequestOneofCase . ActivityRequest )
152161 {
153- this . RunBackgroundTask ( workItem , ( ) => this . OnRunActivityAsync ( workItem . ActivityRequest ) ) ;
162+ this . RunBackgroundTask (
163+ workItem ,
164+ ( ) => this . OnRunActivityAsync ( workItem . ActivityRequest , workItem . CompletionToken ) ) ;
154165 }
155166 else if ( workItem . RequestCase == P . WorkItem . RequestOneofCase . EntityRequest )
156167 {
157- this . RunBackgroundTask ( workItem , ( ) => this . OnRunEntityBatchAsync ( workItem . EntityRequest ) ) ;
168+ this . RunBackgroundTask (
169+ workItem ,
170+ ( ) => this . OnRunEntityBatchAsync ( workItem . EntityRequest , workItem . CompletionToken ) ) ;
171+ }
172+ else if ( workItem . RequestCase == P . WorkItem . RequestOneofCase . HealthPing )
173+ {
174+ // No-op
158175 }
159176 else
160177 {
@@ -188,7 +205,7 @@ void RunBackgroundTask(P.WorkItem? workItem, Func<Task> handler)
188205 } ) ;
189206 }
190207
191- async Task OnRunOrchestratorAsync ( P . OrchestratorRequest request )
208+ async Task OnRunOrchestratorAsync ( P . OrchestratorRequest request , string completionToken )
192209 {
193210 OrchestratorExecutionResult ? result = null ;
194211 P . TaskFailureDetails ? failureDetails = null ;
@@ -248,14 +265,16 @@ async Task OnRunOrchestratorAsync(P.OrchestratorRequest request)
248265 response = ProtoUtils . ConstructOrchestratorResponse (
249266 request . InstanceId ,
250267 result . CustomStatus ,
251- result . Actions ) ;
268+ result . Actions ,
269+ completionToken ) ;
252270 }
253271 else
254272 {
255273 // This is the case for failures that happened *outside* the orchestrator executor
256274 response = new P . OrchestratorResponse
257275 {
258276 InstanceId = request . InstanceId ,
277+ CompletionToken = completionToken ,
259278 Actions =
260279 {
261280 new P . OrchestratorAction
@@ -279,7 +298,7 @@ async Task OnRunOrchestratorAsync(P.OrchestratorRequest request)
279298 await this . sidecar . CompleteOrchestratorTaskAsync ( response ) ;
280299 }
281300
282- async Task OnRunActivityAsync ( P . ActivityRequest request )
301+ async Task OnRunActivityAsync ( P . ActivityRequest request , string completionToken )
283302 {
284303 OrchestrationInstance instance = request . OrchestrationInstance . ToCore ( ) ;
285304 string rawInput = request . Input ;
@@ -336,12 +355,13 @@ async Task OnRunActivityAsync(P.ActivityRequest request)
336355 TaskId = request . TaskId ,
337356 Result = output ,
338357 FailureDetails = failureDetails ,
358+ CompletionToken = completionToken ,
339359 } ;
340360
341361 await this . sidecar . CompleteActivityTaskAsync ( response ) ;
342362 }
343363
344- async Task OnRunEntityBatchAsync ( P . EntityBatchRequest request )
364+ async Task OnRunEntityBatchAsync ( P . EntityBatchRequest request , string completionToken )
345365 {
346366 var coreEntityId = DTCore . Entities . EntityId . FromString ( request . InstanceId ) ;
347367 EntityId entityId = new ( coreEntityId . Name , coreEntityId . Key ) ;
@@ -400,7 +420,7 @@ async Task OnRunEntityBatchAsync(P.EntityBatchRequest request)
400420 }
401421
402422 // convert the result to protobuf format and send it back
403- P . EntityBatchResult response = batchResult . ToEntityBatchResult ( ) ;
423+ P . EntityBatchResult response = batchResult . ToEntityBatchResult ( completionToken ) ;
404424 await this . sidecar . CompleteEntityTaskAsync ( response ) ;
405425 }
406426 }
0 commit comments