Orkestra.EventEnvelope (orkestra v0.2.0)

Copy Markdown View Source

Wraps a domain event with dispatch and delivery context.

Unlike command envelopes, event envelopes track delivery to multiple handlers. An event is a broadcast — it can be handled by many subscribers, each tracked independently.

Structure

%EventEnvelope{
  event: %AssessmentCompleted{...},
  status: :pending,
  published_at: nil,
  handlers: %{
    "GenerateReport" => :succeeded,
    "NotifyUser" => :pending
  }
}

Summary

Functions

Whether all handlers have completed (succeeded, failed, or skipped).

Returns the event id.

Returns the event type.

Marks a specific handler as failed.

Marks a specific handler as processing.

Marks a specific handler as skipped.

Marks a specific handler as succeeded.

Marks the envelope as published.

Returns the event metadata.

Registers a handler for tracking.

Wraps an event in an envelope.

Types

handler_status()

@type handler_status() :: :pending | :processing | :succeeded | :failed | :skipped

status()

@type status() :: :pending | :published | :partially_handled | :handled | :failed

t()

@type t() :: %Orkestra.EventEnvelope{
  event: Orkestra.Event.t(),
  handlers: %{required(String.t()) => handler_status()},
  published_at: DateTime.t() | nil,
  status: status()
}

Functions

all_handled?(event_envelope)

@spec all_handled?(t()) :: boolean()

Whether all handlers have completed (succeeded, failed, or skipped).

event_id(event_envelope)

@spec event_id(t()) :: String.t()

Returns the event id.

event_type(event_envelope)

@spec event_type(t()) :: String.t()

Returns the event type.

mark_handler_failed(env, handler_name)

@spec mark_handler_failed(t(), String.t()) :: t()

Marks a specific handler as failed.

mark_handler_processing(env, handler_name)

@spec mark_handler_processing(t(), String.t()) :: t()

Marks a specific handler as processing.

mark_handler_skipped(env, handler_name)

@spec mark_handler_skipped(t(), String.t()) :: t()

Marks a specific handler as skipped.

mark_handler_succeeded(env, handler_name)

@spec mark_handler_succeeded(t(), String.t()) :: t()

Marks a specific handler as succeeded.

mark_published(env)

@spec mark_published(t()) :: t()

Marks the envelope as published.

metadata(event_envelope)

@spec metadata(t()) :: Orkestra.Metadata.t() | nil

Returns the event metadata.

register_handler(env, handler_name)

@spec register_handler(t(), String.t()) :: t()

Registers a handler for tracking.

wrap(event)

@spec wrap(Orkestra.Event.t()) :: t()

Wraps an event in an envelope.