From 0bb95ec06fec3e391002f368a970501d86cb3744 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sat, 30 Jan 2021 14:43:18 +0100 Subject: [PATCH] Update RunWorkflow activity to return Done if child workflow finished synchronously --- .../RunWorkflow/{Activities => }/RunWorkflow.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) rename src/core/Elsa.Core/Activities/Workflows/RunWorkflow/{Activities => }/RunWorkflow.cs (86%) diff --git a/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/Activities/RunWorkflow.cs b/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs similarity index 86% rename from src/core/Elsa.Core/Activities/Workflows/RunWorkflow/Activities/RunWorkflow.cs rename to src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs index 4608bb603..aecffe7ee 100644 --- a/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/Activities/RunWorkflow.cs +++ b/src/core/Elsa.Core/Activities/Workflows/RunWorkflow/RunWorkflow.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -46,13 +47,17 @@ namespace Elsa.Activities.Workflows var cancellationToken = context.CancellationToken; var workflowBlueprint = await FindWorkflowBlueprintAsync(cancellationToken); var workflowInstance = await _workflowScheduler.RunWorkflowAsync(workflowBlueprint!, TenantId, Input, CorrelationId, ContextId, cancellationToken); + var workflowStatus = workflowInstance.WorkflowStatus; + ChildWorkflowInstanceId = workflowInstance.Id; return Mode switch { RunWorkflowMode.FireAndForget => Done(), - RunWorkflowMode.Blocking => Suspend(), - _ => Suspend() + RunWorkflowMode.Blocking when workflowStatus == WorkflowStatus.Finished => Done(), + RunWorkflowMode.Blocking when workflowStatus == WorkflowStatus.Suspended => Suspend(), + RunWorkflowMode.Blocking when workflowStatus == WorkflowStatus.Faulted => Fault($"Workflow {workflowInstance.Id} faulted"), + _ => throw new ArgumentOutOfRangeException(nameof(Mode)) }; }