Cizen.Saga behaviour (Cizen v0.17.0) View Source

The saga behaviour

Example

defmodule SomeSaga do
  use Cizen.Saga
  defstruct []

  @impl true
  def init(_id, %__MODULE__{}) do
    saga
  end

  @impl true
  def handle_event(_id, _event, state) do
    state
  end
end

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Starts a saga which finishes when the current process exits.

Returns the pid for the given saga ID.

Returns the saga struct for the given saga ID.

Returns the module for a saga.

Resumes a saga with the given state.

Starts a saga linked to the current process

Callbacks

Invoked when the saga receives an event.

Invoked when the saga is started. Saga.Started event will be dispatched after this callback.

Invoked when the saga is resumed.

Link to this section Types

Specs

lifetime() :: pid() | {atom(), node()} | atom() | nil

Specs

state() :: any()

Specs

t() :: struct()

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Specs

fork(t()) :: Cizen.SagaID.t()

Starts a saga which finishes when the current process exits.

Specs

get_pid(Cizen.SagaID.t()) :: {:ok, pid()} | :error

Returns the pid for the given saga ID.

Specs

get_saga(Cizen.SagaID.t()) :: {:ok, t()} | :error

Returns the saga struct for the given saga ID.

Specs

module(t()) :: module()

Returns the module for a saga.

Link to this function

resume(id, saga, state, lifetime \\ nil)

View Source

Specs

resume(Cizen.SagaID.t(), t(), state(), pid() | nil) :: GenServer.on_start()

Resumes a saga with the given state.

Specs

start_link(t()) :: GenServer.on_start()

Starts a saga linked to the current process

Link to this function

start_saga(id, saga, lifetime)

View Source

Link to this section Callbacks

Link to this callback

handle_event(arg1, arg2, state)

View Source

Specs

handle_event(Cizen.SagaID.t(), Cizen.Event.t(), state()) :: state()

Invoked when the saga receives an event.

Returned value will be used as the next state to pass handle_event/3 callback.

Specs

init(Cizen.SagaID.t(), t()) :: state()

Invoked when the saga is started. Saga.Started event will be dispatched after this callback.

Returned value will be used as the next state to pass handle_event/3 callback.

Specs

resume(Cizen.SagaID.t(), t(), state()) :: state()

Invoked when the saga is resumed.

Returned value will be used as the next state to pass handle_event/3 callback.

This callback is predefined. The default implementation is here:

def resume(id, saga, state) do
  init(id, saga)
  state
end