SquidMesh.Runtime.StateMachine (squid_mesh v0.1.0-alpha.3)

Copy Markdown View Source

Explicit run lifecycle state machine for the Squid Mesh runtime.

The runtime coordinator and the later Jido-backed executor should consume this module as the single source of truth for valid run-state transitions. It defines the workflow run lifecycle without mixing in step execution or persistence concerns.

Summary

Functions

Returns the states that may be reached directly from the current state.

Reports whether a transition is valid.

Reports whether the runtime may schedule another step while the run is in the given state.

Returns all valid run states.

Reports whether a state is terminal.

Validates a requested state transition.

Types

state()

@type state() :: SquidMesh.Run.status()

transition_error()

@type transition_error() ::
  {:unknown_state, atom()}
  | {:invalid_transition, from_state :: state(), to_state :: state()}

Functions

allowed_transitions(state)

@spec allowed_transitions(state()) ::
  {:ok, [state()]} | {:error, {:unknown_state, atom()}}

Returns the states that may be reached directly from the current state.

can_transition?(from_state, to_state)

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

Reports whether a transition is valid.

schedule_next_step?(state)

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

Reports whether the runtime may schedule another step while the run is in the given state.

states()

@spec states() :: [state()]

Returns all valid run states.

terminal?(state)

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

Reports whether a state is terminal.

transition(from_state, to_state)

@spec transition(state(), state()) :: {:ok, state()} | {:error, transition_error()}

Validates a requested state transition.