Spectre.GAM.GovernedAct.DispatchState (Spectre v0.4.0)

Copy Markdown View Source

Compact lifecycle index for executor-mediated Acts.

Pending dispatches remain a MapSet because expiry, authority changes and reconciliation scan that small hot set repeatedly. Terminal dispatches share one mutually-exclusive index: an Act either consumed one Attempt or was cancelled. The durable Attempt and cancellation event remain in the ledger; this module only reads and updates their disposable projection indexes.

Summary

Functions

Returns the Attempt bound to an Act, or nil before/without execution.

Returns whether an Act has consumed an Attempt.

Returns the cancellation bound to an Act, or nil when not cancelled.

Returns terminal cancellation entries without materializing another index.

Returns whether an Act's dispatch was cancelled.

Returns pending executor Acts whose pinned Mandate has expired.

Returns the validated Act and pinned Mandate behind each pending dispatch.

Returns whether an Act is waiting at the executor boundary.

Returns the hot set of Acts still eligible to consume a Grant.

Returns the terminal dispatch state for an Act, if one exists.

Types

cancellation()

@type cancellation() :: %{
  cause_ref: String.t(),
  reason:
    :mandate_revoked
    | :mandate_restricted
    | :mandate_expired
    | :disputed_evidence,
  cancelled_at: non_neg_integer()
}

terminal()

@type terminal() :: {:attempt, String.t()} | {:cancelled, cancellation()}

Functions

attempt_ref(state, act_ref)

@spec attempt_ref(Spectre.GAM.GovernedAct.State.t(), String.t()) :: String.t() | nil

Returns the Attempt bound to an Act, or nil before/without execution.

attempted?(state, act_ref)

@spec attempted?(Spectre.GAM.GovernedAct.State.t(), String.t()) :: boolean()

Returns whether an Act has consumed an Attempt.

cancellation(state, act_ref)

@spec cancellation(Spectre.GAM.GovernedAct.State.t(), String.t()) ::
  cancellation() | nil

Returns the cancellation bound to an Act, or nil when not cancelled.

cancellations(state)

@spec cancellations(Spectre.GAM.GovernedAct.State.t()) :: Enumerable.t()

Returns terminal cancellation entries without materializing another index.

cancelled?(state, act_ref)

@spec cancelled?(Spectre.GAM.GovernedAct.State.t(), String.t()) :: boolean()

Returns whether an Act's dispatch was cancelled.

expired(state, time)

@spec expired(Spectre.GAM.GovernedAct.State.t(), integer()) ::
  {:ok, [{Spectre.GAM.Act.t(), Spectre.GAM.Mandate.t()}]} | {:error, term()}

Returns pending executor Acts whose pinned Mandate has expired.

pending(state)

@spec pending(Spectre.GAM.GovernedAct.State.t()) ::
  {:ok, [{Spectre.GAM.Act.t(), Spectre.GAM.Mandate.t()}]} | {:error, term()}

Returns the validated Act and pinned Mandate behind each pending dispatch.

pending?(state, act_ref)

Returns whether an Act is waiting at the executor boundary.

pending_refs(state)

@spec pending_refs(Spectre.GAM.GovernedAct.State.t()) :: MapSet.t(String.t())

Returns the hot set of Acts still eligible to consume a Grant.

terminal(state, act_ref)

@spec terminal(Spectre.GAM.GovernedAct.State.t(), String.t()) :: terminal() | nil

Returns the terminal dispatch state for an Act, if one exists.