Spectre.Operation.Runtime.Support (Spectre v0.3.0)

Copy Markdown View Source

Shared vocabulary for the operation runtime modules.

Small pure helpers used across Spectre.Operation.Runtime and its Contract/Transitions/Results/Controls/Recovery submodules: controller callback invocation, reduced controller contexts, event-spec builders and option/portability utilities. Intended to be imported by those modules.

Summary

Functions

Default maximum retained loop artifacts.

Builds the payload for attempt-started events.

Builds the payload for budget-exhaustion events.

Invokes a controller callback, capturing crashes as tagged errors.

Builds the reduced context passed to controller callbacks.

Builds one event spec.

Maximum retained invalidation entries.

Accepts a map or keyword option, tagging invalid shapes with the field.

Puts a key only when the value is present.

Normalizes a keyword list to a map, dropping invalid shapes.

Reads the deterministic clock from the environment.

Reads one option from a map with a default.

Validates a value as portable, tagging failures as operational.

Reduces an arbitrary failure term to a privacy-safe atom class.

Maximum retained loop results.

Classifies a trigger value into its declared trigger type.

Maximum retained applied updates.

Builds the payload for wait-related events.

Functions

artifact_limit()

@spec artifact_limit() :: pos_integer()

Default maximum retained loop artifacts.

attempt_event(attempt)

@spec attempt_event(Spectre.Operation.Attempt.t()) :: map()

Builds the payload for attempt-started events.

budget_event(dimension, consumed, limit)

@spec budget_event(atom(), term(), term()) :: map()

Builds the payload for budget-exhaustion events.

callback(module, function, args)

@spec callback(module(), atom(), [term()]) :: {:ok, term()} | {:error, term()}

Invokes a controller callback, capturing crashes as tagged errors.

controller_context(loop, env)

@spec controller_context(Spectre.Operation.Loop.t() | nil, map()) :: map()

Builds the reduced context passed to controller callbacks.

event(type, payload \\ %{})

@spec event(atom(), map()) :: %{type: atom(), payload: map()}

Builds one event spec.

invalidation_limit()

@spec invalidation_limit() :: pos_integer()

Maximum retained invalidation entries.

map_option(value, field)

@spec map_option(term(), atom()) :: {:ok, map()} | {:error, term()}

Accepts a map or keyword option, tagging invalid shapes with the field.

maybe_put_map(map, key, value)

@spec maybe_put_map(map(), term(), term()) :: map()

Puts a key only when the value is present.

normalize_map(value)

@spec normalize_map(term()) :: map()

Normalizes a keyword list to a map, dropping invalid shapes.

now(env)

@spec now(map()) :: integer()

Reads the deterministic clock from the environment.

option(opts, key, default \\ nil)

@spec option(map(), term(), term()) :: term()

Reads one option from a map with a default.

portable(value, path)

@spec portable(term(), [term()]) :: :ok | {:error, term()}

Validates a value as portable, tagging failures as operational.

reason_class(reason)

@spec reason_class(term()) :: atom()

Reduces an arbitrary failure term to a privacy-safe atom class.

result_limit()

@spec result_limit() :: pos_integer()

Maximum retained loop results.

trigger_class(type)

@spec trigger_class(term()) :: atom()

Classifies a trigger value into its declared trigger type.

update_limit()

@spec update_limit() :: pos_integer()

Maximum retained applied updates.

wait_event(wait, loop, extra \\ %{})

@spec wait_event(Spectre.Operation.Wait.t(), Spectre.Operation.Loop.t(), map()) ::
  map()

Builds the payload for wait-related events.