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

Copy Markdown View Source

Phase-owned state and transitions for one extension stop operation.

Summary

Functions

Attaches the worker and acknowledgement identity for an editor finalizer.

Records the worker performing termination or cleanup.

Moves to cleanup and records its worker.

Moves directly to editor finalization when no active lease exists.

Moves the stop barrier to editor unload.

Moves the stop operation to runtime termination.

Builds a clean retry after cleanup failed.

Clears a fired or cancelled drain timer.

Records completion of editor effects and merges a finalizer result.

Records an explicit finalizer failure.

Clears completed or failed worker bookkeeping.

Adds another stop caller.

Merges an unload or completion result into finalizer failure state.

Builds an initial quiescing stop transition.

Queues a start intent behind this stop.

Records a terminal-runtime cleanup failure.

Remembers a failed drain request so unload can be aborted correctly.

Replaces the failed-start reason after projection also fails.

Starts a cleanup-only retry for one caller.

Restarts quiescence retry state for one caller.

Records that this stop is rolling back a failed start.

Clears runtime identity after its DOWN arrives during stop.

Marks the code source drained and clears timer ownership.

Replaces stop waiters when a queued stop is transferred from a start.

Types

completion()

@type completion() :: :stop | {:start_failure, term(), [GenServer.from()]}

queued_start()

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

stage()

@type stage() ::
  :quiescing
  | :draining
  | :editor_finalize
  | :editor_unload
  | :terminating
  | :cleanup

t()

@type t() :: %Minga.Extension.Instance.StopContext{
  completion: completion(),
  drain_done?: boolean(),
  drain_ref: reference() | nil,
  drain_timer: reference() | nil,
  editor_done?: boolean(),
  editor_ref: reference() | nil,
  exit_kind: :explicit | :normal | :crash,
  exit_reason: term(),
  finalizer_error: term() | nil,
  runtime: Minga.Extension.Instance.Runtime.t() | nil,
  stage: stage(),
  start_waiters: [queued_start()],
  token: reference() | nil,
  waiters: [GenServer.from()],
  worker: Minga.Extension.Instance.Worker.t() | nil
}

Functions

attach_finalizer(context, worker)

@spec attach_finalizer(t(), Minga.Extension.Instance.Worker.t()) :: t()

Attaches the worker and acknowledgement identity for an editor finalizer.

attach_worker(context, worker)

@spec attach_worker(t(), Minga.Extension.Instance.Worker.t()) :: t()

Records the worker performing termination or cleanup.

begin_cleanup(context, worker)

@spec begin_cleanup(t(), Minga.Extension.Instance.Worker.t()) :: t()

Moves to cleanup and records its worker.

begin_drain(context, token, drain_ref, timer)

@spec begin_drain(t(), reference(), reference(), reference()) :: t()

Begins lease draining.

begin_editor_finalize(context)

@spec begin_editor_finalize(t()) :: t()

Moves directly to editor finalization when no active lease exists.

begin_editor_unload(context)

@spec begin_editor_unload(t()) :: t()

Moves the stop barrier to editor unload.

begin_termination(context)

@spec begin_termination(t()) :: t()

Moves the stop operation to runtime termination.

cleanup_retry(context, opts \\ [])

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

Builds a clean retry after cleanup failed.

clear_drain_timer(context)

@spec clear_drain_timer(t()) :: t()

Clears a fired or cancelled drain timer.

editor_effects_done(context, result)

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

Records completion of editor effects and merges a finalizer result.

fail_finalizer(context, reason)

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

Records an explicit finalizer failure.

finish_work(context)

@spec finish_work(t()) :: t()

Clears completed or failed worker bookkeeping.

join(context, from)

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

Adds another stop caller.

merge_finalizer_result(context, result)

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

Merges an unload or completion result into finalizer failure state.

new(waiter, exit_kind, exit_reason, runtime)

@spec new(
  GenServer.from() | nil,
  :explicit | :normal | :crash,
  term(),
  Minga.Extension.Instance.Runtime.t() | nil
) :: t()

Builds an initial quiescing stop transition.

queue_start(context, start)

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

Queues a start intent behind this stop.

record_terminal_failure(context, failure)

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

Records a terminal-runtime cleanup failure.

remember_failed_drain(context, token, drain_ref)

@spec remember_failed_drain(t(), reference(), reference()) :: t()

Remembers a failed drain request so unload can be aborted correctly.

replace_start_failure(context, reason, start_waiters)

@spec replace_start_failure(t(), term(), [GenServer.from()]) :: t()

Replaces the failed-start reason after projection also fails.

retry_cleanup(context, from)

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

Starts a cleanup-only retry for one caller.

retry_quiescence(context, from)

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

Restarts quiescence retry state for one caller.

rollback_start(context, reason, start_waiters, stop_waiters)

@spec rollback_start(t(), term(), [GenServer.from()], [GenServer.from()]) :: t()

Records that this stop is rolling back a failed start.

runtime_exited(context)

@spec runtime_exited(t()) :: t()

Clears runtime identity after its DOWN arrives during stop.

source_drained(context)

@spec source_drained(t()) :: t()

Marks the code source drained and clears timer ownership.

transfer_waiters(context, waiters)

@spec transfer_waiters(t(), [GenServer.from()]) :: t()

Replaces stop waiters when a queued stop is transferred from a start.