Packages
journey
0.0.9
0.10.58
0.10.57
0.10.56
0.10.55
0.10.54
0.10.53
0.10.52
0.10.51
0.10.50
0.10.49
0.10.48
0.10.47
0.10.46
0.10.45
0.10.44
0.10.43
0.10.41
0.10.40
0.10.39
0.10.38
0.10.37
0.10.36
0.10.35
0.10.34
0.10.33
0.10.32
0.10.31
0.10.30
0.10.29
0.10.28
0.10.27
0.10.26
0.10.25
0.10.24
0.10.23
0.10.22
0.0.9
retired
0.0.8
0.0.7
0.0.6
0.0.5
0.0.3
0.0.2
Journey is a library for defining and running durable workflows with persistence, reliability, and scalability.
Retired package: not currently supported
Current section
Files
Jump to
Current section
Files
lib/step.ex
defmodule Journey.Step do
@moduledoc ~S"""
The data structure for defining a step in a process.
## Example: Using Journey.Step to Define a Process
iex> _process = %Journey.Process{
...> process_id: "horoscopes-r-us",
...> steps: [
...> %Journey.Step{name: :first_name},
...> %Journey.Step{name: :birth_month},
...> %Journey.Step{name: :birth_day},
...> %Journey.Step{
...> name: :astrological_sign,
...> func: fn _values ->
...> # Everyone is a Taurus!
...> {:ok, "taurus"}
...> end,
...> blocked_by: [
...> %Journey.BlockedBy{step_name: :birth_month, condition: :provided},
...> %Journey.BlockedBy{step_name: :birth_day, condition: :provided}
...> ]
...> },
...> %Journey.Step{
...> name: :horoscope,
...> func: fn values ->
...> name = values[:first_name].value
...> sign = values[:astrological_sign].value
...> {
...> :ok,
...> "#{name}! You are a #{sign}! Now is the perfect time to smash the racist patriarchy!"
...> }
...> end,
...> blocked_by: [
...> %Journey.BlockedBy{step_name: :first_name, condition: :provided},
...> %Journey.BlockedBy{step_name: :astrological_sign, condition: :provided}
...> ]
...> }
...> ]
...> }
"""
@doc false
@derive Jason.Encoder
@enforce_keys [:name]
defstruct [
:name,
func: nil,
blocked_by: []
# TODO: add retry policy
]
@typedoc """
Stores the definition of a process step.
## name
The name of the step, some examples:
:first_name
"horoscope"
"offer_rate"
## func
The function that computes the value for the step.
The function accepts one parameter, which contains the current state of the execution.
When the function computes the value, it should return it as part of a tuple: `{:ok, value}`.
If the function was unable to compute the value, with a retriable error, it should return the tuple `{:retriable, error_details}`.
Any other value will be treated as a non-retriable error.
## blocked_by
A collection of conditions that must be be true for the computation to take place.
TODO: examples. make those into functions.
"""
@type t :: %__MODULE__{
name: String.t(),
func: (map() -> {:ok | :retriable | :error, any()}),
blocked_by: list()
}
end