Reference

AddTraxSchedulerLiveness

Package Trax.SchedulerNamespace Trax.Scheduler.ExtensionsSource SchedulerLivenessHealthCheckExtensions.cs

Registers an ASP.NET Core health check, through SchedulerLivenessHealthCheckExtensions, that reports unhealthy when the JobDispatcher has not completed a polling cycle within a threshold. Unlike a process or port probe, this catches a scheduler that is up but dispatching nothing. A cycle still running counts from when it began, and the check reports healthy while dispatch is paused or when the host runs no JobDispatcher (InMemory); see Health & Liveness.

Signature

public static IHealthChecksBuilder AddTraxSchedulerLiveness(
    this IHealthChecksBuilder builder,
    string name = "scheduler-liveness",
    TimeSpan? threshold = null,
    HealthStatus failureStatus = HealthStatus.Unhealthy,
    IEnumerable<string>? tags = null
)

Parameters

ParameterTypeDefaultDescription
namestringscheduler-livenessThe health check name
thresholdTimeSpan?nullStaleness threshold. When null, uses SchedulerConfiguration.SchedulerLivenessThreshold, falling back to max(JobDispatcherPollingInterval * 10, 30s)
failureStatusHealthStatusUnhealthyThe status reported when stale
tagsIEnumerable<string>?nullTags for filtering health checks

Returns

IHealthChecksBuilder, for continued fluent chaining.

Behavior

  • The scheduler registers the underlying ISchedulerLivenessMonitor automatically. The JobDispatcher's polling loop stamps it after each successful cycle, including empty no-op polls. The interface only exposes StartedAt and LastDispatchCompletedAt; recording a cycle is internal to the dispatcher.
  • Before the first cycle completes, the check measures from scheduler startup, so a cold start is healthy within the grace window but a scheduler that never dispatches still trips.
  • The check writes lastDispatchCompletedAt, ageSeconds, and thresholdSeconds into its result data.
  • The threshold can also be set on the scheduler builder with .SchedulerLivenessThreshold(TimeSpan); the threshold argument here overrides it.

Examples

builder.Services.AddHealthChecks().AddTraxSchedulerLiveness();
 
var host = builder.Build();
host.MapHealthChecks("/health");

With a custom threshold and a degraded (non-failing) status:

using Microsoft.Extensions.Diagnostics.HealthChecks;
 
builder.Services
    .AddHealthChecks()
    .AddTraxSchedulerLiveness(
        threshold: TimeSpan.FromSeconds(20),
        failureStatus: HealthStatus.Degraded,
        tags: ["scheduler"]
    );

See also