From 2ae438002d006da20cf3ac3b97f1800eee35ce15 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 10 May 2023 21:46:11 +0200 Subject: [PATCH] Fix that flowchart doesn't complete The issue was that the "has pending work" check considered *any* scheduled activity, regardless of the owner. Instead, the flowchart should check the scheduler for any work that *it* scheduled. --- .../Activities/Flowchart/Activities/Flowchart.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs index a8ae9d8b0..6706bcd93 100644 --- a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs +++ b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs @@ -128,10 +128,9 @@ public class Flowchart : Container if (!children.Any()) { var workflowExecutionContext = context.ReceiverActivityExecutionContext.WorkflowExecutionContext; - var scheduler = workflowExecutionContext.Scheduler; // If there is no pending work, complete the flowchart activity. - var hasPendingWork = scheduler.HasAny; + var hasPendingWork = HasPendingWork(workflowExecutionContext); if (!hasPendingWork) await flowchartActivityExecutionContext.CompleteActivityAsync(); @@ -141,6 +140,19 @@ public class Flowchart : Container context.StopPropagation(); } + /// + /// Checks if there is any pending work for the flowchart. + /// + private bool HasPendingWork(WorkflowExecutionContext workflowExecutionContext) + { + var scheduler = workflowExecutionContext.Scheduler; + var workItems = scheduler.List(); + var activityNodeIds = workItems.Select(x => x.ActivityId).ToList(); + var flowchartChildNodeIds = Activities.Select(workflowExecutionContext.FindNodeByActivity).Select(x => x.NodeId).ToList(); + var hasPendingWork = activityNodeIds.Intersect(flowchartChildNodeIds).Any(); + return hasPendingWork; + } + private bool HaveAllLeafsExecuted(FlowScope scope) { var leafs = Activities.Where(x => Connections.All(y => y.Source != x)).ToList();