Caddy.State (Caddy v2.3.1)

View Source

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

StateDescriptionAllowed Operations
:initializingLibrary starting upNone (transient)
:unconfiguredNo Caddyfile setset_caddyfile/1, get_state/0
:configuredCaddyfile set, not syncedsync_to_caddy/0, set_caddyfile/1, clear_config/0
:syncedConfiguration pushed successfullyAll operations
:degradedWas synced, Caddy not respondingsync_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

ModeEmpty Config Behavior
External (default)Valid - stays in :unconfigured
EmbeddedCannot 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

state()

@type state() :: :initializing | :unconfigured | :configured | :synced | :degraded

transition_event()

@type transition_event() ::
  :startup_empty
  | :startup_with_config
  | :config_set
  | :config_cleared
  | :sync_success
  | :sync_failure
  | :health_ok
  | :health_fail

Functions

configured?(arg1)

@spec configured?(state()) :: boolean()

Check if the given state indicates configuration is present.

degraded?(arg1)

@spec degraded?(state()) :: boolean()

Check if the given state indicates a problem.

describe(atom)

@spec describe(state()) :: String.t()

Get human-readable description of a state.

initial_state(bool)

@spec initial_state(has_config :: boolean()) :: state()

Get the initial state based on whether there is saved configuration.

ready?(arg1)

@spec ready?(state()) :: boolean()

Check if the given state indicates the system is ready to serve.

transition(current_state, event)

@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.

transition!(current_state, event)

@spec transition!(state(), transition_event()) :: state()

Compute the next state, raising on invalid transition.

valid_transition?(from_state, to_state)

@spec valid_transition?(state(), state()) :: boolean()

Check if a transition from from_state to to_state is valid.