@@ -101,13 +101,6 @@ public Task StartAsync(CancellationToken cancellationToken)
101101 return Task . CompletedTask ;
102102 }
103103
104- private void SubscribeToEvents ( )
105- {
106- _messageBrokerSubscriberService . SubscribeAsync ( _options . Value . Messaging . Topics . TaskDispatchRequest , _options . Value . Messaging . Topics . TaskDispatchRequest , TaskDispatchEventReceivedCallback ) ;
107- _messageBrokerSubscriberService . SubscribeAsync ( _options . Value . Messaging . Topics . TaskCallbackRequest , _options . Value . Messaging . Topics . TaskCallbackRequest , TaskCallbackEventReceivedCallback ) ;
108- _messageBrokerSubscriberService . SubscribeAsync ( _options . Value . Messaging . Topics . TaskCancellationRequest , _options . Value . Messaging . Topics . TaskCancellationRequest , TaskCancelationEventCallback ) ;
109- }
110-
111104 public Task StopAsync ( CancellationToken cancellationToken )
112105 {
113106 _logger . ServiceStopping ( ServiceName ) ;
@@ -121,6 +114,39 @@ public Task StopAsync(CancellationToken cancellationToken)
121114 return Task . CompletedTask ;
122115 }
123116
117+ private static JsonMessage < TaskUpdateEvent > GenerateUpdateEventMessage < T > (
118+ JsonMessage < T > message ,
119+ string executionId ,
120+ string workflowInstanceId ,
121+ string taskId ,
122+ ExecutionStatus executionStatus ,
123+ List < Messaging . Common . Storage > ? outputs = null )
124+ {
125+ Guard . Against . Null ( message , nameof ( message ) ) ;
126+ Guard . Against . Null ( executionStatus , nameof ( executionStatus ) ) ;
127+
128+ var body = new TaskUpdateEvent
129+ {
130+ CorrelationId = message . CorrelationId ,
131+ ExecutionId = executionId ,
132+ Reason = executionStatus . FailureReason ,
133+ Status = executionStatus . Status ,
134+ ExecutionStats = executionStatus . Stats ,
135+ WorkflowInstanceId = workflowInstanceId ,
136+ TaskId = taskId ,
137+ Message = executionStatus . Errors ,
138+ Outputs = outputs ?? new List < Messaging . Common . Storage > ( ) ,
139+ } ;
140+ return new JsonMessage < TaskUpdateEvent > ( body , TaskManagerApplicationId , message . CorrelationId ) ;
141+ }
142+
143+ private void SubscribeToEvents ( )
144+ {
145+ _messageBrokerSubscriberService . SubscribeAsync ( _options . Value . Messaging . Topics . TaskDispatchRequest , _options . Value . Messaging . Topics . TaskDispatchRequest , TaskDispatchEventReceivedCallback ) ;
146+ _messageBrokerSubscriberService . SubscribeAsync ( _options . Value . Messaging . Topics . TaskCallbackRequest , _options . Value . Messaging . Topics . TaskCallbackRequest , TaskCallbackEventReceivedCallback ) ;
147+ _messageBrokerSubscriberService . SubscribeAsync ( _options . Value . Messaging . Topics . TaskCancellationRequest , _options . Value . Messaging . Topics . TaskCancellationRequest , TaskCancelationEventCallback ) ;
148+ }
149+
124150 private async Task TaskCallbackEventReceivedCallback ( MessageReceivedEventArgs args )
125151 {
126152 await TaskCallBackGeneric < TaskCallbackEvent > ( args , HandleTaskCallback ) ;
@@ -200,8 +226,12 @@ private async Task HandleCancellationTask(JsonMessage<TaskCancellationEvent> mes
200226 {
201227 throw new InvalidOperationException ( "Task Event data not found." ) ;
202228 }
229+
203230 var taskRunner = typeof ( ITaskPlugin ) . CreateInstance < ITaskPlugin > ( serviceProvider : _scope . ServiceProvider , typeString : pluginAssembly , _serviceScopeFactory , taskExecEvent ) ;
204231 await taskRunner . HandleTimeout ( message . Body . Identity ) ;
232+
233+ await _taskExecutionStatsRepository . UpdateExecutionStatsAsync ( message . Body , message . CorrelationId ) ;
234+ AcknowledgeMessage ( message ) ;
205235 }
206236 catch ( Exception ex )
207237 {
@@ -515,26 +545,6 @@ private void AcknowledgeMessage<T>(JsonMessage<T> message)
515545 }
516546 }
517547
518- private static JsonMessage < TaskUpdateEvent > GenerateUpdateEventMessage < T > ( JsonMessage < T > message , string executionId , string WorkflowInstanceId , string taskId , ExecutionStatus executionStatus , List < Messaging . Common . Storage > outputs = null )
519- {
520- Guard . Against . Null ( message , nameof ( message ) ) ;
521- Guard . Against . Null ( executionStatus , nameof ( executionStatus ) ) ;
522-
523- var body = new TaskUpdateEvent
524- {
525- CorrelationId = message . CorrelationId ,
526- ExecutionId = executionId ,
527- Reason = executionStatus . FailureReason ,
528- Status = executionStatus . Status ,
529- ExecutionStats = executionStatus . Stats ,
530- WorkflowInstanceId = WorkflowInstanceId ,
531- TaskId = taskId ,
532- Message = executionStatus . Errors ,
533- Outputs = outputs ?? new List < Messaging . Common . Storage > ( ) ,
534- } ;
535- return new JsonMessage < TaskUpdateEvent > ( body , TaskManagerApplicationId , message . CorrelationId ) ;
536- }
537-
538548 //TODO: gh-100 implement retry logic
539549 private async Task SendUpdateEvent ( JsonMessage < TaskUpdateEvent > message )
540550 {
0 commit comments