webhooks

package
v0.0.0-...-36bd69e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

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

View Source
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.

View Source
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

func DispatchIntervalFromEnv() time.Duration

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.

func Sign

func Sign(secret string, ts int64, body []byte) string

Sign returns the X-Sentinel-Signature header value: "t=<unix>,v1=<hex hmac-sha256(secret, "<t>.<body>")>". Exported so tests (and, if ever needed, a CLI verification helper) can compute the same value the dispatcher sends.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL