| | | 1 | | using Elsa.Common; |
| | | 2 | | using Microsoft.Extensions.Diagnostics.HealthChecks; |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Runtime.HealthChecks; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Reports whether the workflow runtime can create clients and is currently accepting new work. |
| | | 9 | | /// </summary> |
| | 3 | 10 | | public class ElsaRuntimeHealthCheck(IWorkflowRuntime workflowRuntime, IQuiescenceSignal quiescenceSignal, ILogger<ElsaRu |
| | | 11 | | { |
| | | 12 | | /// <inheritdoc /> |
| | | 13 | | public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToke |
| | | 14 | | { |
| | | 15 | | try |
| | | 16 | | { |
| | 3 | 17 | | await workflowRuntime.CreateClientAsync(cancellationToken); |
| | | 18 | | |
| | 2 | 19 | | var state = quiescenceSignal.CurrentState; |
| | 2 | 20 | | var data = new Dictionary<string, object> |
| | 2 | 21 | | { |
| | 2 | 22 | | ["category"] = "runtime", |
| | 2 | 23 | | ["acceptingNewWork"] = state.IsAcceptingNewWork, |
| | 2 | 24 | | ["reason"] = state.Reason.ToString(), |
| | 2 | 25 | | ["activeExecutionCycles"] = quiescenceSignal.ActiveExecutionCycleCount |
| | 2 | 26 | | }; |
| | | 27 | | |
| | 2 | 28 | | return state.IsAcceptingNewWork |
| | 2 | 29 | | ? HealthCheckResult.Healthy("Elsa workflow runtime is ready.", data) |
| | 2 | 30 | | : HealthCheckResult.Degraded("Elsa workflow runtime is paused or draining.", data: data); |
| | | 31 | | } |
| | 0 | 32 | | catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) |
| | | 33 | | { |
| | 0 | 34 | | throw; |
| | | 35 | | } |
| | 1 | 36 | | catch (Exception e) when (!e.IsFatal()) |
| | | 37 | | { |
| | 1 | 38 | | logger.LogWarning(e, "Elsa workflow runtime could not create a workflow client."); |
| | 1 | 39 | | return HealthCheckResult.Unhealthy("Elsa workflow runtime could not create a workflow client.", data: new Di |
| | 1 | 40 | | { |
| | 1 | 41 | | ["category"] = "runtime" |
| | 1 | 42 | | }); |
| | | 43 | | } |
| | 3 | 44 | | } |
| | | 45 | | } |