View Source Jido.Workflow.Chain (Jido v1.0.0)
Provides functionality to chain multiple Jido Workflows together with interruption support.
This module allows for sequential execution of workflows, where the output of one workflow becomes the input for the next workflow in the chain. Execution can be interrupted between workflows using an interruption check function.
Examples
iex> interrupt_check = fn -> System.monotonic_time(:millisecond) > @deadline end
iex> Jido.Workflow.Chain.chain([AddOne, MultiplyByTwo], %{value: 5}, interrupt_check: interrupt_check)
{:ok, %{value: 12}}
# When interrupted:
iex> Jido.Workflow.Chain.chain([AddOne, MultiplyByTwo], %{value: 5}, interrupt_check: fn -> true end)
{:interrupted, %{value: 6}}
Summary
Functions
Executes a chain of workflows sequentially with optional interruption support.
Types
Functions
@spec chain([chain_workflow()], map(), keyword()) :: chain_result()
Executes a chain of workflows sequentially with optional interruption support.
Parameters
workflows
: A list of workflows to be executed in order. Each workflow can be a module (the workflow module) or a tuple of{workflow_module, options}
.initial_params
: A map of initial parameters to be passed to the first workflow.opts
: Additional options for the chain execution.
Options
:async
- When set totrue
, the chain will be executed asynchronously (default:false
).:context
- A map of context data to be passed to each workflow.:interrupt_check
- A function that returns boolean, called between workflows to check if chain should be interrupted.
Returns
{:ok, result}
whereresult
is the final output of the chain.{:error, error}
if any workflow in the chain fails.{:interrupted, result}
if the chain was interrupted, containing the last successful result.Task.t()
if the:async
option is set totrue
.