Skip to content

Commit

Permalink
Update FlowNode status terminology in BulkDispatchWorkflows (#5150)
Browse files Browse the repository at this point in the history
* Update FlowNode status terminology in BulkDispatchWorkflows

The terminology for the task completion status has been changed in the BulkDispatchWorkflows class. This includes renaming 'Finished' to 'Complete' in the FlowNode attribute, and when calling CompleteActivityWithOutcomesAsync method. This change makes the status names more consistent across the application.

* Update input description in BulkDispatchWorkflows

The input description for the WaitForCompletion property in the BulkDispatchWorkflows activity has been modified for clarity. The previously mentioned condition about the 'Finished' outcome not triggering has been removed as it was creating confusion.

* Rename 'Finished' instances to 'Completed' instances

The code modifies the keywords related to instance statuses and actions in the Workflow activities, changing the term 'Finished' to 'Completed'. This is a global change, impacting variables, properties, cases, and methods. The update serves to improve the clarity and preciseness of the terms used in the workflow process.

* Add SuppressUnreferencedCode attributes and rename methods

The Elsa.Workflows.Runtime module has been updated to suppress warnings from the new .NET 5.0 UnreferencedCode attribute in two methods. Additionally, the name of the method "CheckIfFinishedAsync" in "BulkDispatchWorkflows.cs" has been renamed to "CheckIfCompletedAsync" for clarity and improved readability.
  • Loading branch information
sfmskywalker committed Mar 29, 2024
1 parent 1b56f5d commit a84f33e
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
using Elsa.Workflows.Runtime.UIHints;
using Elsa.Workflows.Services;
using JetBrains.Annotations;
using System.Diagnostics.CodeAnalysis;

namespace Elsa.Workflows.Runtime.Activities;

/// <summary>
/// Creates new workflow instances of the specified workflow for each item in the data source and dispatches them for execution.
/// </summary>
[Activity("Elsa", "Composition", "Create new workflow instances for each item in the data source and dispatch them for execution.", Kind = ActivityKind.Task)]
[FlowNode("Finished", "Canceled", "Done")]
[FlowNode("Completed", "Canceled", "Done")]
[UsedImplicitly]
public class BulkDispatchWorkflows : Activity
{
private const string DispatchedInstancesCountKey = nameof(DispatchedInstancesCountKey);
private const string FinishedInstancesCountKey = nameof(FinishedInstancesCountKey);
private const string CompletedInstancesCountKey = nameof(CompletedInstancesCountKey);

/// <inheritdoc />
public BulkDispatchWorkflows([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line)
Expand Down Expand Up @@ -73,7 +74,7 @@ public BulkDispatchWorkflows([CallerFilePath] string? source = default, [CallerL
/// True to wait for the child workflow to complete before completing this activity, false to "fire and forget".
/// </summary>
[Input(
Description = "Wait for the dispatched workflows to complete before completing this activity. If set, the Finished outcome will not trigger.",
Description = "Wait for the dispatched workflows to complete before completing this activity.",
DefaultValue = true)]
public Input<bool> WaitForCompletion { get; set; } = new(true);

Expand All @@ -92,7 +93,7 @@ public BulkDispatchWorkflows([CallerFilePath] string? source = default, [CallerL
/// An activity to execute when the child workflow finishes.
/// </summary>
[Port]
public IActivity? ChildFinished { get; set; }
public IActivity? ChildCompleted { get; set; }

/// <summary>
/// An activity to execute when the child workflow faults.
Expand All @@ -101,6 +102,7 @@ public BulkDispatchWorkflows([CallerFilePath] string? source = default, [CallerL
public IActivity? ChildFaulted { get; set; }

/// <inheritdoc />
[RequiresUnreferencedCode("Calls Elsa.Expressions.Helpers.ObjectConverter.ConvertTo<T>(ObjectConverterOptions)")]
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
var waitForCompletion = WaitForCompletion.GetOrDefault(context);
Expand Down Expand Up @@ -203,15 +205,16 @@ private async ValueTask<string> DispatchChildWorkflowAsync(ActivityExecutionCont
return instanceId;
}

[RequiresUnreferencedCode("Calls Elsa.Expressions.Helpers.ObjectConverter.ConvertTo<T>(ObjectConverterOptions)")]
private async ValueTask OnChildWorkflowCompletedAsync(ActivityExecutionContext context)
{
var input = context.WorkflowInput;
var workflowInstanceId = input["WorkflowInstanceId"].ConvertTo<string>()!;
var workflowSubStatus = input["WorkflowSubStatus"].ConvertTo<WorkflowSubStatus>();
var workflowOutput = input["WorkflowOutput"].ConvertTo<IDictionary<string, object>>();
var finishedInstancesCount = context.GetProperty<long>(FinishedInstancesCountKey) + 1;
var finishedInstancesCount = context.GetProperty<long>(CompletedInstancesCountKey) + 1;

context.SetProperty(FinishedInstancesCountKey, finishedInstancesCount);
context.SetProperty(CompletedInstancesCountKey, finishedInstancesCount);

var childInstanceId = new Variable<string>("ChildInstanceId", workflowInstanceId)
{
Expand All @@ -235,26 +238,26 @@ private async ValueTask OnChildWorkflowCompletedAsync(ActivityExecutionContext c
case WorkflowSubStatus.Faulted when ChildFaulted is not null:
await context.ScheduleActivityAsync(ChildFaulted, options);
return;
case WorkflowSubStatus.Finished when ChildFinished is not null:
await context.ScheduleActivityAsync(ChildFinished, options);
case WorkflowSubStatus.Finished when ChildCompleted is not null:
await context.ScheduleActivityAsync(ChildCompleted, options);
return;
default:
await CheckIfFinishedAsync(context);
await CheckIfCompletedAsync(context);
break;
}
}

private async ValueTask OnChildFinishedCompletedAsync(ActivityCompletedContext context)
{
await CheckIfFinishedAsync(context.TargetContext);
await CheckIfCompletedAsync(context.TargetContext);
}

private async ValueTask CheckIfFinishedAsync(ActivityExecutionContext context)
private async ValueTask CheckIfCompletedAsync(ActivityExecutionContext context)
{
var dispatchedInstancesCount = context.GetProperty<long>(DispatchedInstancesCountKey);
var finishedInstancesCount = context.GetProperty<long>(FinishedInstancesCountKey);
var finishedInstancesCount = context.GetProperty<long>(CompletedInstancesCountKey);

if (finishedInstancesCount >= dispatchedInstancesCount)
await context.CompleteActivityWithOutcomesAsync("Finished", "Done");
await context.CompleteActivityWithOutcomesAsync("Completed", "Done");
}
}

0 comments on commit a84f33e

Please sign in to comment.