Opus v0.3.1 Opus.Pipeline

Defines a pipeline.

A pipeline defines a single entry point function to start running the defined stages. A sample pipeline can be:

defmodule ArithmeticPipeline do
  use Opus.Pipeline

  step :to_integer, &:erlang.binary_to_integer/1
  step :double, with: & &1 * 2
end

The pipeline can be run calling a call/1 function which is defined by using Opus.Pipeline. Pipelines are intended to have a single parameter and always return a tagged tuple {:ok, value} | {:error, error}. A stage returning {:error, error} halts the pipeline. The error value is an Opus.PipelineError struct which contains useful information to detect where was the error caused and why.

Exception Handling

All exceptions are converted to {:error, exception} tuples by default. You may let a stage raise an exception by providing the :raise option to a stage as follows:

defmodule ArithmeticPipeline do
  use Opus.Pipeline

  step :to_integer, &:erlang.binary_to_integer/1, raise: [ArgumentError]
end

Stage Filtering

You can select the stages of a pipeline to run using call/2 with the :except and :only options. Example:

# Runs only the stage with the :validate_params name
CreateUserPipeline.call(params, only: [:validate_params]
# Runs all the stages except the selected ones
CreateUserPipeline.call(params, except: :send_notification)

Link to this section Summary

Link to this section Functions

Link to this macro check(name, opts \\ []) (macro)
Link to this macro link(name, opts \\ []) (macro)
Link to this macro step(name, opts \\ []) (macro)
Link to this macro tee(name, opts \\ []) (macro)