Application state machine for Caddy configuration lifecycle.
Tracks the operational state of the Elixir Caddy library, providing clear visibility into whether the system is ready to serve requests.
States
| State | Description | Allowed Operations |
|---|---|---|
:initializing | Library starting up | None (transient) |
:unconfigured | No Caddyfile set | set_caddyfile/1, get_state/0 |
:configured | Caddyfile set, not synced | sync_to_caddy/0, set_caddyfile/1, clear_config/0 |
:synced | Configuration pushed successfully | All operations |
:degraded | Was synced, Caddy not responding | sync_to_caddy/0, health checks |
State Transitions
:initializing → :unconfigured (startup, no saved config)
:initializing → :configured (startup, has saved config)
:unconfigured → :configured (set_caddyfile)
:configured → :synced (sync_to_caddy success)
:configured → :configured (sync_to_caddy failure - stays with error)
:synced → :configured (set_caddyfile - new config needs sync)
:synced → :degraded (health check failure)
:degraded → :synced (health check success or sync success)
:configured → :unconfigured (clear_config)Behavior by Mode
| Mode | Empty Config Behavior |
|---|---|
| External (default) | Valid - stays in :unconfigured |
| Embedded | Cannot start Caddy without config |
Summary
Functions
Check if the given state indicates configuration is present.
Check if the given state indicates a problem.
Get human-readable description of a state.
Get the initial state based on whether there is saved configuration.
Check if the given state indicates the system is ready to serve.
Compute the next state given a transition event.
Compute the next state, raising on invalid transition.
Check if a transition from from_state to to_state is valid.
Types
Functions
Check if the given state indicates configuration is present.
Check if the given state indicates a problem.
Get human-readable description of a state.
Get the initial state based on whether there is saved configuration.
Check if the given state indicates the system is ready to serve.
@spec transition(state(), transition_event()) :: {:ok, state()} | {:error, :invalid_transition}
Compute the next state given a transition event.
Returns {:ok, new_state} for valid transitions, or
{:error, :invalid_transition} for invalid ones.
@spec transition!(state(), transition_event()) :: state()
Compute the next state, raising on invalid transition.
Check if a transition from from_state to to_state is valid.