Journey.Node.UpstreamDependencies (Journey v0.10.30)

Summary

Functions

This function is used to define the conditions under which a node is unblocked. It is intended to be used in the gated_by option of a node. The function takes a list of required upstream nodes and returns a predicate tree that can be used to check if the node is unblocked.

Functions

unblocked_when(r)

unblocked_when(upstream_node_name, f_condition)

This function is used to define the conditions under which a node is unblocked. It is intended to be used in the gated_by option of a node. The function takes a list of required upstream nodes and returns a predicate tree that can be used to check if the node is unblocked.

The predicate tree can be a single node name, a function that takes a value node and returns a boolean, or a combination of these using :and, :or, and :not operations.

The function also supports nested predicate trees, allowing for complex conditions to be defined.

Examples:

iex> import Journey.Node
iex> import Journey.Node.Conditions
iex> import Journey.Node.UpstreamDependencies
iex> _graph =
...>   Journey.new_graph(
...>     "horoscope workflow - unblocked_when doctest",
...>     "v1.0.0",
...>     [
...>       input(:first_name),
...>       input(:birth_day),
...>       input(:birth_month),
...>       input(:suspended),
...>       compute(
...>         :zodiac_sign,
...>         # Computes itself once :birth_month and :birth_day have been provided:
...>         [:birth_month, :birth_day],
...>         fn %{birth_month: _birth_month, birth_day: _birth_day} ->
...>           # Everyone is a Taurus. ;)
...>           {:ok, "Taurus"}
...>         end
...>       ),
...>       compute(
...>         :horoscope,
...>         # Computes itself once :first_name and :zodiac_sign are in place, and if not suspended.
...>         unblocked_when({
...>           :and,
...>           [
...>             {:first_name, &provided?/1},
...>             {:zodiac_sign, &provided?/1},
...>             {:suspended, fn suspended -> suspended.node_value != true end}
...>           ]
...>         }),
...>         fn %{first_name: name, zodiac_sign: zodiac_sign} ->
...>           {:ok, "🍪s await, #{zodiac_sign} #{name}!"}
...>         end
...>       )
...>     ]
...>   )
iex>