Fix issue where workflow never finishes

This commit is contained in:
Sipke Schoorstra 2019-09-17 22:53:11 +02:00
parent f8115219ae
commit 130fee2bd8
2 changed files with 18 additions and 24 deletions

View file

@ -14,9 +14,8 @@ namespace Sample05
builder
.WithId("RecurringWorkflow")
.AsSingleton()
.StartWith<TimerEvent>(x => x.TimeoutExpression = new LiteralExpression<TimeSpan>("00:00:05"), "Timer")
.Then<WriteLine>(x => x.TextExpression = new JavaScriptExpression<string>("`Trigger received. The time is: ${new Date().toISOString()}`"))
.Then("Timer");
.StartWith<TimerEvent>(x => x.TimeoutExpression = new LiteralExpression<TimeSpan>("00:00:05"))
.Then<WriteLine>(x => x.TextExpression = new JavaScriptExpression<string>("`Trigger received. The time is: ${new Date().toISOString()}`"));
}
}
}

View file

@ -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