Syntropy.Webhooks.Registry
(syntropy v0.3.0)
Copy Markdown
Registry of webhook endpoints and their recent delivery attempts.
Registrations live in this GenServer's state and, when persistence is enabled, write through to Postgres so they survive gateway restarts. On startup the registry hydrates from the durable store (scoped to this node id, like knowledge items). Writes degrade like events — a failed Postgres write is recorded in persistence health but never blocks the registration. Delivery logs stay in-memory as a bounded ring buffer.
Summary
Functions
Returns a specification to start this module under a supervisor.
List all registered webhooks with their recent deliveries, newest first.
Active webhooks subscribed to the given runtime event id.
Record one delivery attempt outcome for an endpoint.
Register a webhook endpoint.
Remove one webhook registration.
Clear all registrations (test support).
Update the active flag of one webhook.
Types
@type delivery() :: %{ event_id: String.t(), status: :delivered | :failed, http_status: non_neg_integer() | nil, attempts: non_neg_integer(), error: String.t() | nil, delivered_at: DateTime.t() }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec list(GenServer.server()) :: [{webhook(), [delivery()]}]
List all registered webhooks with their recent deliveries, newest first.
@spec matching(GenServer.server(), String.t()) :: [webhook()]
Active webhooks subscribed to the given runtime event id.
@spec record_delivery(GenServer.server(), String.t(), delivery()) :: :ok
Record one delivery attempt outcome for an endpoint.
@spec register(GenServer.server(), map()) :: {:ok, webhook()} | {:error, [map()]}
Register a webhook endpoint.
attrs must contain a valid http(s) url and a non-empty events list of
runtime event ids (or "*" for all). A secret may be supplied so
platform-managed secrets stay consistent; otherwise one is generated.
@spec remove(GenServer.server(), String.t()) :: :ok | {:error, :not_found}
Remove one webhook registration.
@spec reset(GenServer.server()) :: :ok
Clear all registrations (test support).
@spec set_active(GenServer.server(), String.t(), boolean()) :: {:ok, webhook()} | {:error, :not_found}
Update the active flag of one webhook.
@spec start_link(keyword()) :: GenServer.on_start()