WorkflowStem.Runner (workflow_stem v0.5.0)

Copy Markdown View Source

Host-parameterized runner for Stepwise executions.

The runner owns the FSM walk, wait/resume loop, control checks, checkpoint hooks, and canonical event emission. Hosts provide persistence, live publication, and control-state implementations through adapter modules.

start/3 returns as soon as the runner process has offered itself to the control store and emitted :started; the engine's init/2, which runs the first step's entry action, runs in that process, not in the caller. Everything that happens from the first step on, an init failure included, arrives as events.

Summary

Functions

Starts a run of spec and returns {:ok, execution_id} once its runner process has offered itself to the control store (a store that fails is logged, not fatal) and emitted :started.

Types

opts()

@type opts() :: [
  tenant_id: String.t(),
  execution_id: String.t(),
  workflow_name: String.t(),
  speed: pos_integer(),
  control_store: module(),
  checkpoint_store: module(),
  event_sink: module(),
  engine: module(),
  next_event: (map() -> atom()),
  metadata: map()
]

Functions

replay(event_sink, tenant_id, execution_id, opts \\ [])

@spec replay(module() | nil, String.t(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, term()}

start(spec, inputs \\ %{}, opts \\ [])

@spec start(map(), map(), opts()) :: {:ok, String.t()} | {:error, term()}

Starts a run of spec and returns {:ok, execution_id} once its runner process has offered itself to the control store (a store that fails is logged, not fatal) and emitted :started.

The runner then calls the engine's init/2 (the first step's entry action) itself, so a long first step never blocks the caller. Its outcome arrives as events: an initial state that is ready runs on; one that waits is checkpointed and emits its wait (:checkpoint or :paused) like any later step; an init error, the entry action's or the spec's, marks the run failed and emits :step_failed and :paused with the reason, as does an init that raises ({:init_raised, message}), throws ({:init_threw, value}), exits ({:init_exited, reason}) or returns an unexpected value ({:unexpected_init_result, value}). A runner that does not report started within a second is stopped, and the call returns {:error, :runner_start_timeout}.

start_from_runtime(runtime, opts \\ [])

@spec start_from_runtime(map(), opts()) :: {:ok, String.t()} | {:error, term()}