Job.Pipeline (ci v0.1.1) View Source

High-level interface for running Job-powered pipeline of actions.

A pipeline is a collection of actions which can be executed in sequence or parallel, and which all have to succeed for the job to succeed.

Example

Job.run(
  Pipeline.sequence([
    action_1,
    action_2,
    Pipeline.parallel([action_3, action_4]),
    action_5
  ])
)

Such pipeline can be visually represented as:

                     -> action_3
action_1 -> action_2              -> action_5
                     -> action_4

An action inside a pipeline can be any Job.action/0 that responds with {:ok, result} | {:error, reason}. Other responses are not supported. An action crash will be converted into an {:error, exit_reason} response.

A pipeline succeeds if all of its action succeed. In such case, the response of the pipeline is the list of responses of each action. For the example above, the successful response will be:

{:ok, [
  action_1_response,
  action_2_response,
  [action_3_response, action_4_response],
  action_5_response,
]}

An error response depends on the type of pipeline. A sequence pipeline stops on first error, responding with {:error, reason}. A parallel pipeline waits for all the actions to finish. If any of them responded with an error, the aggregated response will be {:error, [error1, error2, ...]}.

Note that in a nested pipeline, where the top-level element is a sequence, an error response can be {:error, action_error | [action_error]}. In addition, the list of errors might be nested. You can consider using functions such as List.wrap/1 and List.flatten/1 to convert the error(s) into a flat list.

Link to this section Summary

Functions

Returns a specification for running a parallel pipeline as a Job action.

Returns a specification for running a sequential pipeline as a Job action.

Link to this section Functions

Link to this function

parallel(actions, opts \\ [])

View Source

Specs

parallel([Job.action()], [Job.action_opt()]) :: Job.action()

Returns a specification for running a parallel pipeline as a Job action.

The corresponding action will return {:ok, [action_result]} | {:error, [action_error]} See Job.start_action/2 for details.

Link to this function

sequence(actions, opts \\ [])

View Source

Specs

sequence([Job.action()], [Job.action_opt()]) :: Job.action()

Returns a specification for running a sequential pipeline as a Job action.

The corresponding action will return {:ok, [action_result]} | {:error, action_error} See Job.start_action/2 for details.