< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.RuntimeAdmin.StatusResponseFactory
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/RuntimeAdmin/Models.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 23
Coverable lines: 23
Total lines: 105
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MapState(...)100%210%
MapSource(...)0%620%
Build(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/RuntimeAdmin/Models.cs

#LineLine coverage
 1using Elsa.Workflows.Runtime;
 2
 3namespace Elsa.Workflows.Api.Endpoints.RuntimeAdmin;
 4
 5/// <summary>Body for the pause endpoint. The reason is a free-form human-readable string captured on the audit event.</
 6public class PauseRequest
 7{
 8    public string? Reason { get; set; }
 9}
 10
 11/// <summary>Body for the resume endpoint.</summary>
 12[Obsolete("Use FastEndpoints.EmptyRequest instead.")]
 13public class ResumeRequest
 14{
 15}
 16
 17/// <summary>Body for the operator-force drain endpoint.</summary>
 18public class ForceDrainRequest
 19{
 20    public string? Reason { get; set; }
 21}
 22
 23/// <summary>Composite quiescence state surfaced by status / pause / resume responses.</summary>
 24public class QuiescenceStateDto
 25{
 26    public string Reason { get; set; } = null!;
 27    public bool IsAcceptingNewWork { get; set; }
 28    public DateTimeOffset? PausedAt { get; set; }
 29    public DateTimeOffset? DrainStartedAt { get; set; }
 30    public string? PauseReasonText { get; set; }
 31    public string? PauseRequestedBy { get; set; }
 32    public string GenerationId { get; set; } = null!;
 33}
 34
 35/// <summary>Per-ingress-source state surfaced by status / pause / resume responses.</summary>
 36public class IngressSourceStateDto
 37{
 38    public string Name { get; set; } = null!;
 39    public string State { get; set; } = null!;
 40    public string? LastError { get; set; }
 41    public DateTimeOffset? LastTransitionAt { get; set; }
 42}
 43
 44/// <summary>Status / pause / resume response. Idempotent endpoints return the post-request state.</summary>
 45public class StatusResponse
 46{
 47    public QuiescenceStateDto State { get; set; } = null!;
 48    public List<IngressSourceStateDto> Sources { get; set; } = new();
 49    public int ActiveExecutionCycleCount { get; set; }
 50}
 51
 52/// <summary>Force-drain outcome surfaced by the force endpoint.</summary>
 53public class DrainOutcomeDto
 54{
 55    public string OverallResult { get; set; } = null!;
 56    public DateTimeOffset StartedAt { get; set; }
 57    public DateTimeOffset CompletedAt { get; set; }
 58    public TimeSpan PausePhaseDuration { get; set; }
 59    public TimeSpan WaitPhaseDuration { get; set; }
 60    public List<IngressSourceStateDto> Sources { get; set; } = new();
 61    public int ExecutionCyclesForceCancelledCount { get; set; }
 62    public List<string> ForceCancelledInstanceIds { get; set; } = new();
 63}
 64
 65/// <summary>Force-drain endpoint response.</summary>
 66public class ForceDrainResponse
 67{
 68    public DrainOutcomeDto Outcome { get; set; } = null!;
 69}
 70
 71/// <summary>Returned by resume/force endpoints when a drain is already in progress.</summary>
 72public class ConflictResponse
 73{
 74    public string Code { get; set; } = null!;
 75    public StatusResponse State { get; set; } = null!;
 76}
 77
 78internal static class StatusResponseFactory
 79{
 080    public static QuiescenceStateDto MapState(QuiescenceState state) => new()
 081    {
 082        Reason = state.Reason.ToString(),
 083        IsAcceptingNewWork = state.IsAcceptingNewWork,
 084        PausedAt = state.PausedAt,
 085        DrainStartedAt = state.DrainStartedAt,
 086        PauseReasonText = state.PauseReasonText,
 087        PauseRequestedBy = state.PauseRequestedBy,
 088        GenerationId = state.GenerationId,
 089    };
 90
 091    public static IngressSourceStateDto MapSource(IngressSourceSnapshot s) => new()
 092    {
 093        Name = s.Name,
 094        State = s.State.ToString(),
 095        LastError = s.LastError?.Message,
 096        LastTransitionAt = s.LastTransitionAt,
 097    };
 98
 099    public static StatusResponse Build(RuntimeAdminStatus status) => new()
 0100    {
 0101        State = MapState(status.State),
 0102        Sources = status.Sources.Select(MapSource).ToList(),
 0103        ActiveExecutionCycleCount = status.ActiveExecutionCycleCount,
 0104    };
 105}