Minga.Extension.Instance.State (Minga v0.1.0)

Copy Markdown View Source

Pure lifecycle state and phase transitions for one extension Instance.

Summary

Functions

Returns the prepared artifact when available.

Moves the authority to cleanup-failed with a resumable stop context.

Replaces per-request lifecycle collaborators while retaining stable injections.

Moves the authority to a terminal crash phase.

Removes projection fields from a registry snapshot.

Updates declaration identity and collaborators while no transition is active.

Increments the authority-owned crash restart count.

Adds a caller to a transition's stop waiter list.

Moves the authority to a terminal load-error phase.

Constructs a stopped lifecycle state from its declaration.

Stores the immutable current-generation artifact.

Queues a start intent behind a safe stop.

Replaces the reason of the current terminal failure phase.

Moves the authority into the running phase.

Returns runtime identity only from phases that own it.

Removes request-scoped callbacks and timeout overrides.

Moves the authority into a start transition.

Moves the authority to a terminal stopped phase.

Moves the authority into a stop transition with an existing context.

Builds the initial asynchronous stop context.

Moves the authority to the lazy stub phase.

Applies the terminal phase implied by a completed stop context.

Types

phase()

queued_start()

@type queued_start() ::
  {:current, GenServer.from()}
  | {:deferred, GenServer.from(), Minga.Extension.Entry.t()}

t()

@type t() :: %Minga.Extension.Instance.State{
  artifact: :unprepared | {:prepared, Minga.Extension.Instance.Artifact.t()},
  collaborators: keyword(),
  declaration: Minga.Extension.Entry.t(),
  instance_registry: atom(),
  name: atom(),
  phase: phase(),
  registry: GenServer.server(),
  restart_count: non_neg_integer()
}

Functions

artifact(state)

@spec artifact(t()) :: {:ok, Minga.Extension.Instance.Artifact.t()} | :error

Returns the prepared artifact when available.

cleanup_failed(state, reason, retry)

@spec cleanup_failed(t(), term(), Minga.Extension.Instance.StopContext.t()) :: t()

Moves the authority to cleanup-failed with a resumable stop context.

configure(state, collaborators)

@spec configure(
  t(),
  keyword()
) :: t()

Replaces per-request lifecycle collaborators while retaining stable injections.

crashed(state, reason)

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

Moves the authority to a terminal crash phase.

declaration_only(entry)

@spec declaration_only(Minga.Extension.Entry.t()) :: Minga.Extension.Entry.t()

Removes projection fields from a registry snapshot.

declare(state, declaration, registry, collaborators)

@spec declare(t(), Minga.Extension.Entry.t(), GenServer.server(), keyword()) ::
  {:ok, t()} | {:error, term()}

Updates declaration identity and collaborators while no transition is active.

increment_restart(state)

@spec increment_restart(t()) :: t()

Increments the authority-owned crash restart count.

join_stop(state, from)

@spec join_stop(t(), GenServer.from()) :: t()

Adds a caller to a transition's stop waiter list.

load_error(state, reason)

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

Moves the authority to a terminal load-error phase.

new(name, declaration, registry, instance_registry, collaborators)

@spec new(atom(), Minga.Extension.Entry.t(), GenServer.server(), atom(), keyword()) ::
  t()

Constructs a stopped lifecycle state from its declaration.

put_artifact(state, artifact)

@spec put_artifact(t(), Minga.Extension.Instance.Artifact.t()) :: t()

Stores the immutable current-generation artifact.

queue_start(state, queued_start)

@spec queue_start(t(), queued_start()) :: t()

Queues a start intent behind a safe stop.

replace_terminal_failure(state, reason)

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

Replaces the reason of the current terminal failure phase.

running(state, runtime)

@spec running(t(), Minga.Extension.Instance.Runtime.t()) :: t()

Moves the authority into the running phase.

runtime(arg1)

@spec runtime(phase()) :: Minga.Extension.Instance.Runtime.t() | nil

Returns runtime identity only from phases that own it.

stable_collaborators(collaborators)

@spec stable_collaborators(keyword()) :: keyword()

Removes request-scoped callbacks and timeout overrides.

starting(state, context)

@spec starting(t(), Minga.Extension.Instance.StartContext.t()) :: t()

Moves the authority into a start transition.

stopped(state)

@spec stopped(t()) :: t()

Moves the authority to a terminal stopped phase.

stopping(state, context)

@spec stopping(t(), Minga.Extension.Instance.StopContext.t()) :: t()

Moves the authority into a stop transition with an existing context.

stopping(state, waiter, exit_kind, exit_reason)

@spec stopping(t(), GenServer.from() | nil, :explicit | :normal | :crash, term()) ::
  t()

Builds the initial asynchronous stop context.

stubbed(state, artifact)

@spec stubbed(t(), Minga.Extension.Instance.Artifact.t()) :: t()

Moves the authority to the lazy stub phase.

terminal(state, stop_context)

@spec terminal(t(), Minga.Extension.Instance.StopContext.t()) :: t()

Applies the terminal phase implied by a completed stop context.