Spectre.Instance.Lifecycle (Spectre v0.3.0)

Copy Markdown View Source

Independent admission, authority, retention and activation axes for a Definition.

A saved Run authority epoch is lineage only. Authorization always consults the current lifecycle record at admission, commit or dispatch time.

Summary

Functions

Moves the active lifecycle fence atomically for a Definition Activation.

Checks current-time lifecycle authority for a runtime operation.

Fetches a lifecycle or returns a safe default for a known Definition.

Builds the initial active lifecycle represented by an Activation.

Restores lifecycle data without creating atoms.

Returns the stable map key for a Definition lifecycle.

Builds and validates a Definition lifecycle record.

Builds a lifecycle record or raises with its stable reason.

Returns the lifecycle schema version.

Returns portable lifecycle data.

Transitions one axis through revision CAS and monotonic safety rules.

Types

axis()

@type axis() :: :admission | :authority | :retention | :activation

t()

@type t() :: %Spectre.Instance.Lifecycle{
  activation: :active | :inactive,
  admission: :accepting | :draining | :closed,
  authority: :granted | :restricted | :revoked,
  authority_epoch: non_neg_integer(),
  changed_at: non_neg_integer(),
  definition_ref: Spectre.Definition.Ref.t(),
  provenance: map(),
  reason: term(),
  retention: :retained | :gc_eligible | :purged,
  revision: non_neg_integer(),
  schema_version: pos_integer()
}

Functions

activate(lifecycles, current, next, opts \\ [])

@spec activate(
  map(),
  Spectre.Instance.Activation.t() | nil,
  Spectre.Instance.Activation.t(),
  keyword()
) ::
  {:ok, map()} | {:error, term()}

Moves the active lifecycle fence atomically for a Definition Activation.

authorize(lifecycle, operation)

@spec authorize(t(), :new_admission | :continuation | :dispatch | :commit) ::
  :ok | {:error, term()}

Checks current-time lifecycle authority for a runtime operation.

fetch(lifecycles, ref, opts \\ [])

@spec fetch(map(), Spectre.Definition.Ref.t(), keyword()) :: t()

Fetches a lifecycle or returns a safe default for a known Definition.

from_activation(activation)

@spec from_activation(Spectre.Instance.Activation.t()) :: t()

Builds the initial active lifecycle represented by an Activation.

from_data(value)

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

Restores lifecycle data without creating atoms.

key(ref)

@spec key(Spectre.Definition.Ref.t() | t()) :: String.t()

Returns the stable map key for a Definition lifecycle.

new(lifecycle)

@spec new(t() | map() | keyword()) :: {:ok, t()} | {:error, term()}

Builds and validates a Definition lifecycle record.

new!(attrs)

@spec new!(t() | map() | keyword()) :: t()

Builds a lifecycle record or raises with its stable reason.

schema_version()

@spec schema_version() :: pos_integer()

Returns the lifecycle schema version.

to_data(lifecycle)

@spec to_data(t()) :: map()

Returns portable lifecycle data.

transition(lifecycle, axis, value, opts \\ [])

@spec transition(t(), axis(), atom(), keyword()) :: {:ok, t()} | {:error, term()}

Transitions one axis through revision CAS and monotonic safety rules.