Documentation
¶
Overview ¶
Package webhooks implements N3b: the outbound webhook delivery dispatcher. It polls agent_webhooks on a ticker (mirroring apps/processor-go/dlqmonitor's Run/checkOnceRecoverable pattern) and, for each active webhook, fetches any issue_activity events past its cursor and POSTs them, HMAC-signed, to the subscriber's URL. See store/webhooks.go's package doc for the compare-and-swap cursor design and why this is optimistic rather than FOR UPDATE SKIP LOCKED.
Index ¶
Constants ¶
const DefaultDispatchInterval = 5 * time.Second
DefaultDispatchInterval is how often the dispatcher scans for active webhooks with due events, used when WEBHOOK_DISPATCH_INTERVAL is unset or invalid.
const DefaultFailureThreshold = 20
DefaultFailureThreshold is the consecutive-failure count at which a webhook is auto-disabled (status set to 'failed'), used when WEBHOOK_FAILURE_THRESHOLD is unset or invalid.
Variables ¶
This section is empty.
Functions ¶
func DispatchIntervalFromEnv ¶
DispatchIntervalFromEnv reads WEBHOOK_DISPATCH_INTERVAL (a Go duration string, e.g. "5s") or falls back to DefaultDispatchInterval, mirroring dlqmonitor.CheckIntervalFromEnv's parsing pattern.
func EnabledFromEnv ¶
func EnabledFromEnv() bool
EnabledFromEnv reports whether WEBHOOK_DISPATCH_ENABLED is exactly "true". Off by default — main.go only starts the dispatcher goroutine when this is true.
func FailureThresholdFromEnv ¶
func FailureThresholdFromEnv() int
FailureThresholdFromEnv reads WEBHOOK_FAILURE_THRESHOLD or falls back to DefaultFailureThreshold.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
Store store.WebhookStore
Client *http.Client
Interval time.Duration
FailureThreshold int
MaxRetries int
Backoffs []time.Duration
}
Dispatcher polls store for active webhooks and delivers due events to each. Store is declared as store.WebhookStore (an interface) so tests can substitute a fake without a live database — see dispatcher_test.go.
func NewDispatcher ¶
func NewDispatcher(st store.WebhookStore) *Dispatcher
NewDispatcher returns a Dispatcher with the same client timeout and retry/backoff shape as notifiers/telegram.go's TelegramWorker (10s client timeout, 3 attempts, 1s/5s/30s backoff).
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run(ctx context.Context)
Run blocks, ticking on d.Interval (DefaultDispatchInterval if unset) until ctx is done. Intended to be started with `go dispatcher.Run(ctx)`, mirroring dlqmonitor.Monitor.Run.
func (*Dispatcher) Tick ¶
func (d *Dispatcher) Tick(ctx context.Context)
Tick lists every active webhook and attempts one delivery cycle for each. Exported so tests can drive it synchronously without waiting on Run's ticker.