diff --git a/samples/Sample05/RecurringWorkflow.cs b/samples/Sample05/RecurringWorkflow.cs index 67d7253da..6e7f493b5 100644 --- a/samples/Sample05/RecurringWorkflow.cs +++ b/samples/Sample05/RecurringWorkflow.cs @@ -14,9 +14,8 @@ namespace Sample05 builder .WithId("RecurringWorkflow") .AsSingleton() - .StartWith(x => x.TimeoutExpression = new LiteralExpression("00:00:05"), "Timer") - .Then(x => x.TextExpression = new JavaScriptExpression("`Trigger received. The time is: ${new Date().toISOString()}`")) - .Then("Timer"); + .StartWith(x => x.TimeoutExpression = new LiteralExpression("00:00:05")) + .Then(x => x.TextExpression = new JavaScriptExpression("`Trigger received. The time is: ${new Date().toISOString()}`")); } } } \ No newline at end of file diff --git a/src/core/Elsa.Core/Services/WorkflowInvoker.cs b/src/core/Elsa.Core/Services/WorkflowInvoker.cs index ed741f52b..4b410f279 100644 --- a/src/core/Elsa.Core/Services/WorkflowInvoker.cs +++ b/src/core/Elsa.Core/Services/WorkflowInvoker.cs @@ -280,38 +280,33 @@ namespace Elsa.Services WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken) { - // Any other status than Executing means the workflow has ended (because it reached the final activity, was aborted or has faulted). - if (!workflowExecutionContext.Workflow.IsExecuting() && - !workflowExecutionContext.Workflow.IsFaultedOrAborted()) + if (!workflowExecutionContext.HasScheduledHaltingActivities && workflowExecutionContext.Workflow.IsExecuting()) { workflowExecutionContext.Finish(); } else { - if (workflowExecutionContext.HasScheduledHaltingActivities) + // Notify event handlers that halting activities are about to be executed. + await workflowEventHandlers.InvokeAsync( + async x => await x.InvokingHaltedActivitiesAsync(workflowExecutionContext, cancellationToken), + logger + ); + + // Invoke Halted event on activity drivers that halted the workflow. + while (workflowExecutionContext.HasScheduledHaltingActivities) { - // Notify event handlers that halting activities are about to be executed. - await workflowEventHandlers.InvokeAsync( - async x => await x.InvokingHaltedActivitiesAsync(workflowExecutionContext, cancellationToken), - logger + var currentActivity = workflowExecutionContext.PopScheduledHaltingActivity(); + var result = await ExecuteActivityHaltedAsync( + workflowExecutionContext, + currentActivity, + cancellationToken ); - // Invoke Halted event on activity drivers that halted the workflow. - while (workflowExecutionContext.HasScheduledHaltingActivities) - { - var currentActivity = workflowExecutionContext.PopScheduledHaltingActivity(); - var result = await ExecuteActivityHaltedAsync( - workflowExecutionContext, - currentActivity, - cancellationToken - ); - - await result.ExecuteAsync(this, workflowExecutionContext, cancellationToken); - } + await result.ExecuteAsync(this, workflowExecutionContext, cancellationToken); } } - // Notify event handlers that invocation has ended. + // Notify event handlers that workflow execution has ended. await workflowEventHandlers.InvokeAsync( async x => await x.WorkflowInvokedAsync(workflowExecutionContext, cancellationToken), logger