Update Execute endpoint to return workflow state

This commit is contained in:
Sipke Schoorstra 2023-04-21 23:59:39 +02:00
parent 4b77751214
commit 81c85fbdbf
2 changed files with 18 additions and 16 deletions

View file

@ -61,22 +61,23 @@ public class Execute : ElsaEndpoint<Request, Response>
{
var workflowState = await _workflowRuntime.ExportWorkflowStateAsync(result.WorkflowInstanceId, cancellationToken);
await HandleFaultAsync(workflowState!, cancellationToken);
return;
}
// Resume any HTTP bookmarks.
await _httpBookmarkProcessor.ProcessBookmarks(new[] { result }, correlationId, default, cancellationToken);
var workflowState2 = await _workflowRuntime.ExportWorkflowStateAsync(result.WorkflowInstanceId, cancellationToken);
if (workflowState2!.SubStatus == WorkflowSubStatus.Faulted)
else
{
await HandleFaultAsync(workflowState2, cancellationToken);
return;
}
// Resume any HTTP bookmarks.
await _httpBookmarkProcessor.ProcessBookmarks(new[] { result }, correlationId, default, cancellationToken);
if (!HttpContext.Response.HasStarted)
await SendOkAsync(new Response(result.WorkflowInstanceId), cancellationToken);
var workflowState = await _workflowRuntime.ExportWorkflowStateAsync(result.WorkflowInstanceId, cancellationToken);
if (workflowState!.SubStatus == WorkflowSubStatus.Faulted)
{
await HandleFaultAsync(workflowState, cancellationToken);
return;
}
if (!HttpContext.Response.HasStarted)
await SendOkAsync(new Response(workflowState), cancellationToken);
}
}
private async Task HandleFaultAsync(WorkflowState workflowState, CancellationToken cancellationToken)

View file

@ -1,5 +1,6 @@
using System.Text.Json.Serialization;
using Elsa.Workflows.Core.Serialization.Converters;
using Elsa.Workflows.Core.State;
namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Execute;
@ -14,10 +15,10 @@ public class Request
public class Response
{
public Response(string instanceId)
public Response(WorkflowState workflowState)
{
InstanceId = instanceId;
WorkflowState = workflowState;
}
public string InstanceId { get; }
public WorkflowState WorkflowState { get; }
}