Wraps a command with dispatch context: routing, retries, and lifecycle tracking.
The envelope is what the dispatcher and middleware operate on. The command itself is immutable once created; the envelope accumulates context as it flows through the pipeline.
Structure
%CommandEnvelope{
command: %StartAssessment{...},
status: :pending,
dispatched_at: nil,
completed_at: nil,
result: nil,
error: nil,
attempts: 0,
max_retries: 0,
middleware_context: %{}
}
Summary
Functions
Returns the command id.
Returns the command type.
Gets a value from the middleware context.
Marks the envelope as dispatched.
Marks the envelope as failed with an error.
Marks the envelope as rejected (e.g. validation or authorization failure).
Marks the envelope as succeeded with a result.
Returns the command metadata.
Stores a value in the middleware context.
Whether the envelope can be retried.
Wraps a command in an envelope.
Types
@type status() :: :pending | :dispatched | :succeeded | :failed | :rejected
@type t() :: %Orkestra.CommandEnvelope{ attempts: non_neg_integer(), command: Orkestra.Command.t(), completed_at: DateTime.t() | nil, dispatched_at: DateTime.t() | nil, error: term(), max_retries: non_neg_integer(), middleware_context: map(), result: term(), status: status() }
Functions
Returns the command id.
Returns the command type.
Gets a value from the middleware context.
Marks the envelope as dispatched.
Marks the envelope as failed with an error.
Marks the envelope as rejected (e.g. validation or authorization failure).
Marks the envelope as succeeded with a result.
@spec metadata(t()) :: Orkestra.Metadata.t() | nil
Returns the command metadata.
Stores a value in the middleware context.
Whether the envelope can be retried.
@spec wrap( Orkestra.Command.t(), keyword() ) :: t()
Wraps a command in an envelope.
Options
:max_retries— number of retry attempts on failure (default: 0)