Expand description
Service lifecycle state machine for the Janus Supervisor.
Each service managed by the JanusSupervisor
progresses through a well-defined set of states:
┌──────────┐
│ Starting │──────────────────────────┐
└────┬─────┘ │
│ run() entered │ init error
▼ ▼
┌──────────┐ ┌────────────┐
│ Running │───── error ──────▶│ BackingOff │
└────┬─────┘ └──────┬─────┘
│ │
│ cancel / Ok(()) │ retry
│ │
│ ┌────────────────────────────┘
▼ ▼
┌──────────┐ ┌────────────┐
│ Stopping │────────▶│ Terminated │
└──────────┘ └────────────┘The state machine enforces deterministic behaviour:
- Starting: The service is initializing resources (connections, channels).
- Running: The service’s
run()loop is active. - BackingOff: The service failed and is waiting for the exponential backoff timer before the supervisor retries.
- Stopping: A cancellation signal was received; the service is finalizing (flushing WAL, closing connections).
- Terminated: The service has exited cleanly (or the circuit breaker tripped and the supervisor gave up). Terminal state.
The BackingOff state prevents the supervisor from tight-looping on a
persistent failure, which would burn CPU and flood logs.
Structs§
- Service
Lifecycle - Full lifecycle tracker for a single supervised service.
- Service
Lifecycle Snapshot - A point-in-time snapshot of a service’s lifecycle, suitable for
serialization into JSON (e.g., for the
/api/healthendpoint). - Transition
Error - Error returned when an invalid state transition is attempted.
Enums§
- Service
Phase - Lifecycle phase of a supervised service.
- Termination
Reason - Why a service reached the
Terminatedphase.