| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Workflows.Runtime; |
| | | 3 | | using FastEndpoints; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | using Microsoft.AspNetCore.Http; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.RuntimeAdmin.Resume; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// <c>POST /admin/workflow-runtime/resume</c> — clears <see cref="QuiescenceReason.AdministrativePause"/>. |
| | | 11 | | /// Returns 409 Conflict when a drain is in progress (resume is meaningless mid-drain — see edge case in spec). |
| | | 12 | | /// Idempotent on the success path. |
| | | 13 | | /// </summary> |
| | | 14 | | [PublicAPI] |
| | 3 | 15 | | internal sealed class ResumeEndpoint(IWorkflowRuntimeAdminService admin) : ElsaEndpoint<ResumeRequest, StatusResponse> |
| | | 16 | | { |
| | | 17 | | public override void Configure() |
| | | 18 | | { |
| | 3 | 19 | | Post("/admin/workflow-runtime/resume"); |
| | 3 | 20 | | ConfigurePermissions(PermissionNames.ManageWorkflowRuntime); |
| | 3 | 21 | | } |
| | | 22 | | |
| | | 23 | | public override async Task HandleAsync(ResumeRequest req, CancellationToken ct) |
| | | 24 | | { |
| | 0 | 25 | | var status = admin.GetStatus(); |
| | 0 | 26 | | if ((status.State.Reason & QuiescenceReason.Drain) != 0) |
| | | 27 | | { |
| | | 28 | | // Use the discriminated ConflictResponse shape to match ForceDrain's 409 contract; routed via |
| | | 29 | | // HttpContext.Response.WriteAsJsonAsync because Send.ResponseAsync is constrained to TResponse. |
| | 0 | 30 | | HttpContext.Response.StatusCode = StatusCodes.Status409Conflict; |
| | 0 | 31 | | await HttpContext.Response.WriteAsJsonAsync( |
| | 0 | 32 | | new ConflictResponse { Code = "runtime-draining", State = StatusResponseFactory.Build(status) }, |
| | 0 | 33 | | ct); |
| | 0 | 34 | | return; |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | await admin.ResumeAsync(HttpContext.User.Identity?.Name, ct); |
| | 0 | 38 | | await Send.OkAsync(StatusResponseFactory.Build(admin.GetStatus()), ct); |
| | 0 | 39 | | } |
| | | 40 | | } |