Journey.Execution (Journey v0.0.5) View Source

An execution of a process.

An execution gets created when you call

execution = Journey.Process.execute(process)

The execution can then be updated with new values

{:ok, updated_execution} = Journey.Execution.update_value(
    execution.execution_id,
    :first_name,
    "Luigi")

and its can be introspected.

> updated_execution |> Journey.Execution.read_value(:first_name)
{:computed, "Luigi"}

Link to this section Summary

Types

t()

Stores the information related to an execution of a process.

Functions

Get all steps in the execution, and their current state.

Get all the steps in the execution that are blocked by other steps.

Returns a human friendly string containing the summary of the current status of the execution.

Get all the steps in an execution that have yet to receive a value.

Fetches the value contained in a specificified step.

Load an execution from store, given its execution id.

Load an execution from store, given its execution id.

Read value from an execution.

Update a value in an execution, given the execution or execution id. The new value gets immediately persisted. Any steps that become unblocked by this value will start computing.

Link to this section Types

Specs

t() :: %Journey.Execution{
  execution_id: String.t(),
  process: Journey.Process,
  save_version: integer(),
  values: map()
}

Stores the information related to an execution of a process.

execution_id

The id of this execution.

process

The process that this execution is running.

values

The values associated with this execution, in various states of computation.

save_version

The version of this execution. Every time an execution gets updated, it is persisted, and its save_version value gets incremented.

Link to this section Functions

Link to this function

get_all_values(execution_id)

View Source

Specs

get_all_values(t()) :: [
  {:not_computed | :computed | :computing | :failed,
   [status: any(), value: any(), self_computing: boolean(), blocked_by: list()]}
]

Get all steps in the execution, and their current state.

iex(9)> execution_id |> Journey.Execution.get_all_values
[
started_at: [
  status: :computed,
  value: 1615790505,
  self_computing: false,
  blocked_by: []
],
first_name: [
  status: :not_computed,
  value: nil,
  self_computing: false,
  blocked_by: []
],
birth_month: [
  status: :not_computed,
  value: nil,
  self_computing: false,
  blocked_by: []
],
birth_day: [
  status: :not_computed,
  value: nil,
  self_computing: false,
  blocked_by: []
],
astrological_sign: [
  status: :not_computed,
  value: nil,
  self_computing: true,
  blocked_by: [:birth_month, :birth_day]
],
horoscope: [
  status: :not_computed,
  value: nil,
  self_computing: true,
  blocked_by: [:first_name, :astrological_sign]
]
]
Link to this function

get_blocked_steps(execution)

View Source

Specs

get_blocked_steps(t()) :: list()

Get all the steps in the execution that are blocked by other steps.

> execution |> Journey.Execution.get_blocked_steps()
[
  astrological_sign: %Journey.Value{
    name: :astrological_sign,
    status: :not_computed,
    update_time: 0,
    value: nil
  },
  horoscope: %Journey.Value{
    name: :horoscope,
    status: :not_computed,
    update_time: 0,
    value: nil
  }
]

Specs

get_summary(t()) :: String.t()

Returns a human friendly string containing the summary of the current status of the execution.

> execution |> Journey.Execution.get_summary |> IO.puts
Execution Summary
Execution ID: keo56rvimq
Execution started: 2021-03-15 06:41:45Z
Revision: 1
All Steps:
[started_at]: '1615790505'. Blocked by: []. Self-computing: false
[first_name]: 'not_computed'. Blocked by: []. Self-computing: false
[birth_month]: 'not_computed'. Blocked by: []. Self-computing: false
[birth_day]: 'not_computed'. Blocked by: []. Self-computing: false
[astrological_sign]: 'not_computed'. Blocked by: [birth_month, birth_day]. Self-computing: true
[horoscope]: 'not_computed'. Blocked by: [first_name, astrological_sign]. Self-computing: true

:ok
Link to this function

get_unfilled_steps(execution)

View Source

Specs

get_unfilled_steps(t()) :: list()

Get all the steps in an execution that have yet to receive a value.

> Journey.Execution.get_unfilled_steps(execution)
[
  astrological_sign: %Journey.Value{
    name: :astrological_sign,
    status: :not_computed,
    update_time: 0,
    value: nil
  },
  birth_day: %Journey.Value{
    name: :birth_day,
    status: :not_computed,
    update_time: 0,
    value: nil
  },
  birth_month: %Journey.Value{
    name: :birth_month,
    status: :not_computed,
    update_time: 0,
    value: nil
  },
  first_name: %Journey.Value{
    name: :first_name,
    status: :not_computed,
    update_time: 0,
    value: nil
  },
  horoscope: %Journey.Value{
    name: :horoscope,
    status: :not_computed,
    update_time: 0,
    value: nil
  }
]
Link to this function

get_value(execution_id, value_id)

View Source

Fetches the value contained in a specificified step.

iex(1)> Journey.Execution.get_value(execution_id, :birth_day)
26

Specs

load(String.t()) :: {:error, :no_such_execution} | {:ok, t()}

Load an execution from store, given its execution id.

{:ok, execution} = Journey.Execution.load(execution_id)

Specs

load!(String.t()) :: t()

Load an execution from store, given its execution id.

execution = Journey.Execution.load!(execution_id)
Link to this function

read_value(execution, value_name)

View Source

Specs

read_value(t(), atom()) ::
  {:not_computed | :computing | :computed | :failed | :error,
   atom() | nil | Journey.Execution}

Read value from an execution.

> execution |> Journey.Execution.read_value(:first_name)
{:computed, "Mario"}
> execution |> Journey.Execution.read_value(:astrological_sign)
{:computing, nil}
> execution |> Journey.Execution.read_value(:horoscope_name)
{:not_computed, nil}
> execution |> Journey.Execution.read_value(:ssn)
{:error, :unknown_step}
Link to this function

update_value(execution_id, value_name, new_value)

View Source

Specs

update_value(String.t(), atom(), any()) :: {:ok, t()}
update_value(t(), atom(), any()) :: {:ok, t()}

Update a value in an execution, given the execution or execution id. The new value gets immediately persisted. Any steps that become unblocked by this value will start computing.

The function returns a tuple that, in case of success, includes the updated execution.

{:ok, updated_execution} = Journey.Execution.update_value(execution_id, :first_name, "Luigi")
{:unknown_step, _} = Journey.Execution.update_value(execution_id, :ssn, "111-11-11")
{:unknown_execution_id, _} = Journey.Execution.update_value(no_such_execution, :first_name, "Luigi")
Link to this function

update_value!(execution, value_name, new_value)

View Source

Specs

update_value!(t(), atom(), any()) :: t()
Link to this function

wait_for_result(execution, step, timeout_ms \\ 30000, frequency \\ 1000)

View Source