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.
This commit is contained in:
Sipke Schoorstra 2023-05-10 21:46:11 +02:00
parent dcc35469a7
commit 2ae438002d

View file

@ -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();
}
/// <summary>
/// Checks if there is any pending work for the flowchart.
/// </summary>
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();