View Source README
ExPipeline
An opinionated library to build better pipelines.
creating-a-pipeline
Creating a Pipeline
On the module that will implement the pipeline, simplye use Pipeline and you are ready to go.
- A function is considered a step if its name ends with
_stepand accepts exactly two parameters - A function is considered a callback if its name ends with
_callbackand accepts exactly two parameters - Steps and callbacks are executed in the order they are declared
- Steps must always return an ok/error tuple:
{:ok, value}or{:error, error} - If one step fails, following steps will not be executed
- Callbacks are always executed after all steps are called, regardless of the final result.
An example:
defmodule MyModule do
use Pipeline
@doc """
First step of the pipeline
"""
def init_step(value, options) do
# {:ok, updated_value}
# or
# {:error, some_error}
end
@doc """
Second step of the pipeline
"""
def second_step(value, options) do
# {:ok, updated_value}
# or
# {:error, some_error}
end
@doc """
Callback - always executed, results ignored
"""
def report_callback(state, _options) do
MyReportingModule.publish(state)
end
endWith this module in place, you have two options to execute it:
- Calling the
execute/2function from your module - Calling the
execute/3function from thePipelinemodule
Both lines will execute the pipeline:
MyModule.execute(starting_value, options)
Pipeline.execute(MyModule, starting_value, options)
installation
Installation
If available in Hex, the package can be installed
by adding ex_pipeline to your list of dependencies in mix.exs:
def deps do
[
{:ex_pipeline, "~> 0.1.0"}
]
end