From 0b01347f59758d57b17d7c71257ab6f185660c77 Mon Sep 17 00:00:00 2001 From: gardusig Date: Thu, 11 May 2023 18:31:51 -0300 Subject: [PATCH] Improve WorkflowTaskExecutor logic to create a failed task instead of raising an Exception --- Conductor/Client/Worker/WorkflowTaskExecutor.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Conductor/Client/Worker/WorkflowTaskExecutor.cs b/Conductor/Client/Worker/WorkflowTaskExecutor.cs index a51dc4d8..9c05f528 100644 --- a/Conductor/Client/Worker/WorkflowTaskExecutor.cs +++ b/Conductor/Client/Worker/WorkflowTaskExecutor.cs @@ -1,4 +1,5 @@ using Conductor.Client.Interfaces; +using Conductor.Client.Extensions; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -140,8 +141,6 @@ private void ProcessTask(Models.Task task) try { var taskResult = _worker.Execute(task); - taskResult.WorkerId = _workerSettings.WorkerId; - UpdateTask(taskResult); _logger.LogTrace( $"[{_workerSettings.WorkerId}] Done processing task for worker" + $", taskType: {_worker.TaskType}" @@ -149,6 +148,7 @@ private void ProcessTask(Models.Task task) + $", taskId: {task.TaskId}" + $", workflowId: {task.WorkflowInstanceId}" ); + UpdateTask(taskResult); } catch (Exception e) { @@ -159,6 +159,8 @@ private void ProcessTask(Models.Task task) + $", taskId: {task.TaskId}" + $", workflowId: {task.WorkflowInstanceId}" ); + var taskResult = task.Failed(e.Message); + UpdateTask(taskResult); } finally { @@ -168,6 +170,7 @@ private void ProcessTask(Models.Task task) private void UpdateTask(Models.TaskResult taskResult) { + taskResult.WorkerId = taskResult.WorkerId ?? _workerSettings.WorkerId; for (var attemptCounter = 0; attemptCounter < UPDATE_TASK_RETRY_COUNT_LIMIT; attemptCounter += 1) { try