Skip to main content

Module lifecycle

Module lifecycle 

Source
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§

ServiceLifecycle
Full lifecycle tracker for a single supervised service.
ServiceLifecycleSnapshot
A point-in-time snapshot of a service’s lifecycle, suitable for serialization into JSON (e.g., for the /api/health endpoint).
TransitionError
Error returned when an invalid state transition is attempted.

Enums§

ServicePhase
Lifecycle phase of a supervised service.
TerminationReason
Why a service reached the Terminated phase.