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
| Parameter | Type | Default | Description |
|---|---|---|---|
builder | IHealthChecksBuilder | The builder AddHealthChecks() returns | |
name | string | "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
| Situation | Result |
|---|---|
| Every machine reproduces its corpus | Healthy, "Every state machine reproduces its committed corpus." |
| Any machine drifts | Unhealthy, with one line per diff, prefixed by the machine |
A machine ships no corpus (IMachine.Corpus is null) | Skipped, not failed |
- It resolves every
IMachinethat 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 anIHostedServiceat 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
- Runtime integrity, the self-check beside the schema-hash handshake and divergence detection.
- MachineConformance, the same checks run in a test.