From e2cea7310f940273b5abd3cd1600c4a7e371605d Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 4 Aug 2023 22:15:07 +0200 Subject: [PATCH] Update Break behavior to also handle "CompleteComposite" signal --- .../Behaviors/BreakBehavior.cs | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Behaviors/BreakBehavior.cs b/src/modules/Elsa.Workflows.Core/Behaviors/BreakBehavior.cs index 6940fb95b..f2adfc4e8 100644 --- a/src/modules/Elsa.Workflows.Core/Behaviors/BreakBehavior.cs +++ b/src/modules/Elsa.Workflows.Core/Behaviors/BreakBehavior.cs @@ -15,6 +15,19 @@ public class BreakBehavior : Behavior public BreakBehavior(IActivity owner) : base(owner) { OnSignalReceived(OnBreakAsync); + OnSignalReceived(OnCompleteCompositeAsync); + } + + private async ValueTask OnCompleteCompositeAsync(CompleteCompositeSignal signal, SignalContext context) + { + // Cancel each descendant to clear bookmarks and cancel jobs etc. + await CancelDescendantsAsync(context); + + // Remove child activity execution contexts. + await context.ReceiverActivityExecutionContext.RemoveChildrenAsync(); + + // Mark this activity as completed. + await context.ReceiverActivityExecutionContext.CompleteActivityAsync(); } private async ValueTask OnBreakAsync(BreakSignal signal, SignalContext context) @@ -23,11 +36,7 @@ public class BreakBehavior : Behavior context.StopPropagation(); // Cancel each descendant to clear bookmarks and cancel jobs etc. - var descendants = context.ReceiverActivityExecutionContext.ActivityNode.Descendants().Select(x => x.Activity).ToList(); - var workflowExecutionContext = context.SenderActivityExecutionContext.WorkflowExecutionContext; - - foreach (var descendant in descendants) - await workflowExecutionContext.CancelActivityAsync(descendant); + await CancelDescendantsAsync(context); // Remove child activity execution contexts. await context.ReceiverActivityExecutionContext.RemoveChildrenAsync(); @@ -35,4 +44,14 @@ public class BreakBehavior : Behavior // Mark this activity as completed. await context.ReceiverActivityExecutionContext.CompleteActivityAsync(); } + + private async Task CancelDescendantsAsync(SignalContext context) + { + var senderActivity = context.SenderActivityExecutionContext.Activity; + var descendants = context.ReceiverActivityExecutionContext.ActivityNode.Descendants().Select(x => x.Activity).Where(x => x.Id != senderActivity.Id).ToList(); + var workflowExecutionContext = context.ReceiverActivityExecutionContext.WorkflowExecutionContext; + + foreach (var descendant in descendants) + await workflowExecutionContext.CancelActivityAsync(descendant); + } } \ No newline at end of file