Choreo.Lab.DSL.Workflow (Choreo v0.12.0)

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching workflows.

This Lab DSL compiles to the stable, pipe-first Choreo.Workflow builders and returns an ordinary %Choreo.Workflow{}. It is useful for business processes, approvals, Sagas, CI/CD flows, and system-design walkthroughs where the shape of execution matters more than builder ceremony.

Examples

iex> import Choreo.Lab.DSL.Workflow
...> flow = workflow do
...>   backend = swimlane("Backend")
...>   start = begin("Request received")
...>   validate = task("Validate token", swimlane: backend, timeout_ms: 100)
...>   authorized = decision("Authorized?")
...>   accepted = finish("Return 200")
...>   rejected = finish("Return 403")
...>
...>   start ~> validate
...>   validate ~> authorized
...>   authorized ~> accepted |> condition("yes")
...>   failure authorized ~> rejected, "no"
...> end
iex> Enum.sort(Choreo.Workflow.starts(flow))
[:start]
iex> Enum.sort(Choreo.Workflow.ends(flow))
[:accepted, :rejected]

Edges can use generic, typed, or pipe-modified forms:

start ~> validate
decision ~> approved |> condition("yes")
edge task ~> retry_step, retry: "temporary failure"
failure task ~> rollback, "validation failed"
compensation rollback ~> done, "cleanup finished"

Summary

Types

edge_decl()

@type edge_decl() :: %{from: Yog.node_id(), to: Yog.node_id(), opts: keyword()}

node_decl()

@type node_decl() :: %{id: Yog.node_id(), builder: atom(), opts: keyword()}

swimlane_decl()

@type swimlane_decl() :: %{id: String.t(), opts: keyword()}

Functions

begin(arg1 \\ nil, arg2 \\ nil, opts \\ [])

compensates(arg1 \\ nil, arg2 \\ nil, opts \\ [])

compensation(arg1 \\ nil, arg2 \\ nil, opts \\ [])

decision(arg1 \\ nil, arg2 \\ nil, opts \\ [])

done(arg1 \\ nil, arg2 \\ nil, opts \\ [])

end_event(arg1 \\ nil, arg2 \\ nil, opts \\ [])

error(arg1 \\ nil, arg2 \\ nil, opts \\ [])

event(arg1 \\ nil, arg2 \\ nil, opts \\ [])

failure(arg1 \\ nil, arg2 \\ nil, opts \\ [])

finish(arg1 \\ nil, arg2 \\ nil, opts \\ [])

fork(arg1 \\ nil, arg2 \\ nil, opts \\ [])

gateway(arg1 \\ nil, arg2 \\ nil, opts \\ [])

join(arg1 \\ nil, arg2 \\ nil, opts \\ [])

lane(arg1 \\ nil, arg2 \\ nil, opts \\ [])

merge(arg1 \\ nil, arg2 \\ nil, opts \\ [])

retry(arg1 \\ nil, arg2 \\ nil, opts \\ [])

rollback(arg1 \\ nil, arg2 \\ nil, opts \\ [])

sequence(arg1 \\ nil, arg2 \\ nil, opts \\ [])

signal(arg1 \\ nil, arg2 \\ nil, opts \\ [])

split(arg1 \\ nil, arg2 \\ nil, opts \\ [])

start(arg1 \\ nil, arg2 \\ nil, opts \\ [])

step(arg1 \\ nil, arg2 \\ nil, opts \\ [])

swimlane(arg1 \\ nil, arg2 \\ nil, opts \\ [])

task(arg1 \\ nil, arg2 \\ nil, opts \\ [])

taxonomy()

@spec taxonomy() :: %{
  swimlanes: [atom()],
  nodes: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Returns the vocabulary supported by the workflow DSL.

iex> taxonomy = Choreo.Lab.DSL.Workflow.taxonomy()
iex> :task in taxonomy.nodes
true
iex> :swimlane in taxonomy.swimlanes
true
iex> :failure in taxonomy.edges
true

terminal(arg1 \\ nil, arg2 \\ nil, opts \\ [])

then(arg1 \\ nil, arg2 \\ nil, opts \\ [])

timeout(arg1 \\ nil, arg2 \\ nil, opts \\ [])

timer(arg1 \\ nil, arg2 \\ nil, opts \\ [])

verbs()

@spec verbs() :: map()

Compatibility alias for taxonomy/0.

workflow(list)

(macro)

Builds a %Choreo.Workflow{} from a compact Lab DSL block.

workflow(opts, list)

(macro)