Journey.Process (Journey v0.0.5) View Source

Link to this section Summary

Types

t()

Holds the definition of a process.

Functions

Starts a new execution of the process.

Link to this section Types

Specs

t() :: %Journey.Process{
  name: String.t(),
  steps: [Journey.Step.t()],
  version: String.t()
}

Holds the definition of a process.

Example: A process for Computing Horoscopes.

iex> _process = %Journey.Process{
...>  name: "horoscopes-r-us",
...>  version: "0.0.1",
...>  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: [
...>        birth_month: :provided,
...>        birth_day: :provided
...>      ]
...>    },
...>    %Journey.Step{
...>      name: :horoscope,
...>      func: fn values ->
...>        name = values[:first_name].value
...>        sign = Atom.to_string(values[:astrological_sign].value)
...>        {
...>          :ok,
...>          "#{name}! You are a #{sign}! Now is the perfect time to smash the racist patriarchy!"
...>        }
...>      end,
...>      blocked_by: [
...>        first_name: :provided,
...>        astrological_sign: :provided
...>      ]
...>    }
...>  ]
...> }

Link to this section Functions

Specs

execute(t()) :: Journey.Execution.t()

Starts a new execution of the process.

Example

iex> process = %Journey.Process{
...>  name: "horoscopes-r-us",
...>  version: "0.0.1",
...>  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: [
...>        birth_month: :provided,
...>        birth_day: :provided
...>      ]
...>    },
...>    %Journey.Step{
...>      name: :horoscope,
...>      func: fn values ->
...>        name = values[:first_name].value
...>        sign = Atom.to_string(values[:astrological_sign].value)
...>        {
...>          :ok,
...>          "#{name}! You are a #{sign}! Now is the perfect time to smash the racist patriarchy!"
...>        }
...>      end,
...>      blocked_by: [
...>        first_name: :provided,
...>        astrological_sign: :provided
...>      ]
...>    }
...>  ]
...> }
iex>
iex> # Start a new execution of the process.
iex> execution = Journey.Process.execute(process)
iex>
iex>
iex> {:ok, execution} = Journey.Execution.update_value(execution, :first_name, "Luigi")
iex> {:not_computed, _} = Journey.Execution.read_value(execution, :astrological_sign)
iex> {:ok, execution} = Journey.Execution.update_value(execution, :birth_month, 4)
iex> {:ok, execution} = Journey.Execution.update_value(execution, :birth_day, 29)
iex> :timer.sleep(100) # Give :astrological_sign's function a bit of time to run.
iex> {:computed, :taurus} = execution.execution_id |> Journey.Execution.load!() |> Journey.Execution.read_value(:astrological_sign)
iex> :timer.sleep(100) # Give :horoscope's function a bit of time to run.
iex> {:computed, horoscope} = execution.execution_id |> Journey.Execution.load!() |> Journey.Execution.read_value(:horoscope)
iex> horoscope
"Luigi! You are a taurus! Now is the perfect time to smash the racist patriarchy!"