From 92dd03c68cae9f9e2897cf540d9e98a6cbc87a24 Mon Sep 17 00:00:00 2001 From: Frank Wagner Date: Wed, 25 Oct 2023 13:10:58 +0200 Subject: [PATCH] errors in status event - workflow keeps running (#7) When a error occurs in status event handler of a parent task the error handler incorrectly sets the sending task to failed and not the parent task. --- .../Workflow/FailedOperationHandler.cs | 8 +++++++- .../Events/OperationTaskStatusEventBase.cs | 2 +- .../Rebus.Operations.Primitives/IOperationTaskMessage.cs | 1 - .../IOperationTaskStatusEvent.cs | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskStatusEvent.cs diff --git a/src/Rebus.Operations/Rebus.Operations.Core/Workflow/FailedOperationHandler.cs b/src/Rebus.Operations/Rebus.Operations.Core/Workflow/FailedOperationHandler.cs index 004b069..bd59d3b 100644 --- a/src/Rebus.Operations/Rebus.Operations.Core/Workflow/FailedOperationHandler.cs +++ b/src/Rebus.Operations/Rebus.Operations.Core/Workflow/FailedOperationHandler.cs @@ -33,10 +33,16 @@ public async Task Handle(IFailed failedMessage) failedMessage.Message.TaskId, failedMessage.ErrorDescription ); + var failedTaskId = failedMessage.Message.TaskId; + + // assign errors on status events to initiating task + if(failedMessage.Message is IOperationTaskStatusEvent statusEvent) + failedTaskId = statusEvent.InitiatingTaskId; + await _operationMessaging.DispatchTaskStatusEventAsync( OperationTaskStatusEvent.Failed( failedMessage.Message.OperationId, failedMessage.Message.InitiatingTaskId, - failedMessage.Message.TaskId, new ErrorData() { ErrorMessage = failedMessage.ErrorDescription }, + failedTaskId, new ErrorData() { ErrorMessage = failedMessage.ErrorDescription }, _workflowOptions.JsonSerializerOptions)); diff --git a/src/Rebus.Operations/Rebus.Operations.Primitives/Events/OperationTaskStatusEventBase.cs b/src/Rebus.Operations/Rebus.Operations.Primitives/Events/OperationTaskStatusEventBase.cs index 9e8a3b4..10f16ee 100644 --- a/src/Rebus.Operations/Rebus.Operations.Primitives/Events/OperationTaskStatusEventBase.cs +++ b/src/Rebus.Operations/Rebus.Operations.Primitives/Events/OperationTaskStatusEventBase.cs @@ -4,7 +4,7 @@ namespace Dbosoft.Rebus.Operations.Events; #nullable enable -public class OperationTaskStatusEventBase : IOperationTaskMessage +public class OperationTaskStatusEventBase : IOperationTaskStatusEvent { public OperationTaskStatusEventBase() {} diff --git a/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskMessage.cs b/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskMessage.cs index e7af6ac..8d2e24c 100644 --- a/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskMessage.cs +++ b/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskMessage.cs @@ -13,5 +13,4 @@ public interface IOperationTaskMessage Guid TaskId { get; } } - } \ No newline at end of file diff --git a/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskStatusEvent.cs b/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskStatusEvent.cs new file mode 100644 index 0000000..1f67a66 --- /dev/null +++ b/src/Rebus.Operations/Rebus.Operations.Primitives/IOperationTaskStatusEvent.cs @@ -0,0 +1,6 @@ +namespace Dbosoft.Rebus.Operations; + +public interface IOperationTaskStatusEvent : IOperationTaskMessage +{ + +} \ No newline at end of file