Spectre.Operation.Control.Command (Spectre v0.3.0)

Copy Markdown View Source

Durable, idempotent command for controlling one operational loop.

Summary

Functions

Marks the command as :applied, stamping completed_at with the current time.

Marks the command as :committed, stamping committed_at with the current time.

Builds a pending control command for loop_id.

Marks the command as :rejected with reason, stamping completed_at with the current time.

Validates the command's identity, action, mode, timestamps and portability.

Types

t()

@type t() :: %Spectre.Operation.Control.Command{
  action: atom(),
  base_revision: non_neg_integer() | nil,
  causation_id: String.t() | nil,
  committed_at: non_neg_integer() | nil,
  completed_at: non_neg_integer() | nil,
  correlation_id: String.t(),
  desired_state: :active | :paused | :terminal | nil,
  id: String.t(),
  loop_id: String.t(),
  metadata: map(),
  mode: :safe | :immediate,
  payload: term(),
  provenance: map(),
  rejection: term(),
  requested_at: non_neg_integer(),
  status: :pending | :committed | :applied | :rejected
}

Functions

applied(command)

@spec applied(t()) :: t()

Marks the command as :applied, stamping completed_at with the current time.

committed(command)

@spec committed(t()) :: t()

Marks the command as :committed, stamping committed_at with the current time.

new(loop_id, action, opts \\ [])

@spec new(String.t(), atom(), keyword()) :: t()

Builds a pending control command for loop_id.

action must be one of :pause, :update, :resume, :stop, :renew, :trigger or :update_and_resume; the desired loop state is derived from it unless :desired_state is given. Missing ids and requested_at default to fresh UUIDv7s and the current time. Raises ArgumentError on an invalid mode.

rejected(command, reason)

@spec rejected(t(), term()) :: t()

Marks the command as :rejected with reason, stamping completed_at with the current time.

validate(command)

@spec validate(t()) :: :ok | {:error, term()}

Validates the command's identity, action, mode, timestamps and portability.

Returns :ok, or {:error, reason} naming the first invalid field or the status whose timestamps are inconsistent.