Hephaestus.Core.Workflow behaviour (hephaestus v0.3.1)

Copy Markdown View Source

Behaviour and compile-time validation helpers for workflow modules.

Workflows are declared with use Hephaestus.Workflow and must expose:

  • start/0
  • transit/3 — static clauses ignore context with _ctx, dynamic clauses use @targets

The Hephaestus.Workflow macro extracts the workflow DAG at compile time, validates it, and generates helper functions for runtime coordination.

Summary

Types

Static or configured step target.

Functions

Validates the workflow DAG built from the given start target and edges.

Types

edge()

@type edge() :: %{
  from: module(),
  event: atom(),
  targets: [module()],
  dynamic?: boolean()
}

target()

@type target() :: module() | {module(), map() | struct()}

Static or configured step target.

Callbacks

start()

@callback start() :: target()

transit(from, event, context)

@callback transit(
  from :: module(),
  event :: atom(),
  context :: Hephaestus.Core.Context.t()
) ::
  target() | [target()] | nil

Functions

validate!(workflow_module, start, edges, env)

@spec validate!(
  module(),
  module() | {module(), map() | struct()},
  [edge()],
  Macro.Env.t()
) :: %{
  graph: Graph.t(),
  predecessors: %{optional(module()) => MapSet.t(module())}
}

Validates the workflow DAG built from the given start target and edges.

Checks that the graph is acyclic, all steps are reachable from start, leaf nodes terminate at Hephaestus.Steps.Done, fan-out branches converge, context keys don't collide, and step events match transit clauses.

Returns the validated graph and a predecessors map. Raises CompileError on any violation.