Kathikon.Job.StateMachine (Kathikon v0.2.1)

Copy Markdown View Source

Validates job state transitions for Kathikon v0.2.0.

Invalid transitions return {:error, {:invalid_transition, from, to}}. Terminal states reject all outbound transitions.

Allowed transitions

scheduled -> available
scheduled -> cancelled
available -> claimed
available -> cancelled
claimed -> running
claimed -> cancelled
running -> completed
running -> retryable
running -> failed
running -> waiting_for_children
waiting_for_children -> completed
waiting_for_children -> failed
retryable -> scheduled
retryable -> available
failed -> dead
failed -> discarded

Claiming also moves :retryable jobs to :claimed when they are due.

Summary

Functions

Returns true when to is allowed from from.

Returns the list of states reachable from state.

Returns all supported states.

Returns true when the job is in a terminal state.

Validates a transition. Returns :ok or {:error, {:invalid_transition, from, to}}.

Functions

allowed?(from, to)

@spec allowed?(atom(), atom()) :: boolean()

Returns true when to is allowed from from.

reachable_from(state)

@spec reachable_from(atom()) :: [atom()]

Returns the list of states reachable from state.

states()

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

Returns all supported states.

terminal?(state)

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

Returns true when the job is in a terminal state.

transition(from, to)

@spec transition(atom(), atom()) ::
  :ok | {:error, {:invalid_transition, atom(), atom()}}

Validates a transition. Returns :ok or {:error, {:invalid_transition, from, to}}.