Reference

AddTraxStateMachineSelfCheck

Package Trax.StateMachine.PersistenceNamespace Trax.StateMachine.PersistenceSource StateMachineSelfCheckHealthCheck.cs, SnapshotSelfCheck.cs

Registers the state-machine runtime self-check as an ASP.NET Core health check. On every check it replays each registered machine's committed differential corpus through the engine this build shipped, and reports Unhealthy with every diff when a machine no longer reproduces it.

Signature

namespace Trax.StateMachine.Persistence;
 
public static class StateMachineHealthCheckExtensions
{
    public static IHealthChecksBuilder AddTraxStateMachineSelfCheck(
        this IHealthChecksBuilder builder,
        string name = "state-machines"
    );
}

Parameters

ParameterTypeDefaultDescription
builderIHealthChecksBuilderThe builder AddHealthChecks() returns
namestring"state-machines"The health check's registration name

Returns

The IHealthChecksBuilder, for chaining. There is no tags parameter; to tag the check, register it under a name of your own and filter by name.

Behavior

SituationResult
Every machine reproduces its corpusHealthy, "Every state machine reproduces its committed corpus."
Any machine driftsUnhealthy, with one line per diff, prefixed by the machine
A machine ships no corpus (IMachine.Corpus is null)Skipped, not failed
  • It resolves every IMachine that AddStateMachines registered, so it needs no configuration and picks up a new machine without one.
  • The replay runs synchronously on each call and ignores the cancellation token. Its cost grows with corpus size.
  • It calls SnapshotSelfCheck.Run(machines), which a host can also call itself, for example from an IHostedService at startup. Registering the health check does not gate startup.

Example

builder.Services.AddTrax(trax =>
    trax.AddEffects(effects => effects.UsePostgres(connectionString))
        .AddStateMachines(typeof(CheckoutMachine).Assembly)
        .AddMediator(typeof(CheckoutMachine).Assembly));
 
builder.Services.AddHealthChecks().AddTraxStateMachineSelfCheck();
 
var host = builder.Build();
host.MapHealthChecks("/health");

See also