Graphex
A library for composing and executing task graphs in elixir.
Add as Dependency
{:graphex, "~> 0.1.1"}
Also, be sure to add :graphex to your application's list of OTP applications since it has a supervision tree that must be started before using the library.
Usage
Each node is represented by a separate process so tasks will run in parallel if possible. Failed nodes will be retried automatically per the default supervision restart settings.
incr = fn node ->
fn r -> r[node] + 1
end
result = exec_graph :e, [
[name: :a, fun: fn _ -> 0 end],
[name: :b, fun: incr.(:a), deps: [:a]],
[name: :c, fun: incr.(:b), deps: [:b]],
[name: :d, fun: incr.(:b), deps: [:b]],
[name: :e, fun: incr.(:c), deps: [:c]],
]
assert result == 3Errors and Retries
Each node can be automatically retried if the function causes the process to die. In order to automatically retry, just set the :tries attribute to a number greater than 1.
[name: :b, fun: something_that_might_error(), deps: [:some_data], tries: 3],
This would automatically retry vertex :b up to 3 times.
If the node fails all tries, it will publish {:error, {:graphex, some_error}} to all of the nodes that depend on it.