Spectre.ActionHooks (Spectre v0.3.0)

Copy Markdown View Source

Runs lifecycle hooks for executed actions.

Hooks are intentionally post-execution. They are useful for audit records, delivery acknowledgements, integration events, or cleanup that should happen after the user-facing action result exists.

Summary

Functions

Runs hooks configured for an executed action lifecycle event.

Types

hook()

@type hook() :: %{
  action: Spectre.Action.ref(),
  on: hook_event() | atom(),
  run: {module(), atom()} | function(),
  opts: keyword()
}

hook_event()

@type hook_event() :: :delivered

Functions

run(agent, event, result, ctx, opts \\ [])

@spec run(
  module(),
  hook_event() | atom(),
  Spectre.Result.t(),
  Spectre.Context.t() | map(),
  keyword()
) ::
  :ok | {:error, [term()]}

Runs hooks configured for an executed action lifecycle event.

:ok = Spectre.ActionHooks.run(MyAgent, :delivered, result, ctx)

Both agent-level hooks and hooks attached to a completed action effect are considered. Errors are accumulated so one failing hook does not hide another.