Spectre.Monitor (Spectre v0.3.0)

Copy Markdown View Source

Failure boundary for host delivery around a Spectre agent.

Spectre.Monitor wraps host delivery code and creates a fallback through injected callbacks when that code fails. This keeps databases, queues, and transport APIs outside the runtime while still giving applications one place to produce a user-safe failure response.

Summary

Functions

Runs a monitored host operation and creates a fallback when it fails.

Renders the configured failure fallback prompt.

Types

callback_result()

@type callback_result() :: {:ok, map()} | {:error, term()}

context()

@type context() :: map()

Functions

dispatch(agent, context, opts)

@spec dispatch(module(), context(), keyword()) :: callback_result()

Runs a monitored host operation and creates a fallback when it fails.

Spectre.Monitor.dispatch(MyAgent, context,
  run: fn -> deliver_turn.() end,
  fallback_exists?: &MyApp.Fallbacks.exists?/1,
  create_fallback: &MyApp.Fallbacks.create/3
)

fallback_text(agent, context, reason, opts \\ [])

@spec fallback_text(module(), context(), term(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Renders the configured failure fallback prompt.

{:ok, text} = Spectre.Monitor.fallback_text(MyAgent, context, :timeout)