Documentation
¶
Overview ¶
Package notifier multiplexes a single Postgres LISTEN connection to the producers, the cancel handler and the elector, and reconnects with jittered backoff when the connection is lost.
n, err := notifier.New(notifier.Config{Listener: l, Clock: clk, OnConnect: wakeAll})
n.Subscribe("foreman_insert", func(queue string) { wake(queue) })
go n.Run(ctx)
Index ¶
Constants ¶
View Source
const ( DefaultMinBackoff = 100 * time.Millisecond DefaultMaxBackoff = 5 * time.Second // DefaultIdleTimeout is how long the connection may stay quiet before it // is pinged; a connection that died silently is found within twice this. DefaultIdleTimeout = 30 * time.Second )
Defaults for reconnect backoff.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Listener job.Listener
Clock clock.Clock
Logger *slog.Logger
// MinBackoff and MaxBackoff bound the jittered reconnect delay.
MinBackoff time.Duration
MaxBackoff time.Duration
// IdleTimeout is how long to wait for a notification before pinging the
// connection.
IdleTimeout time.Duration
// OnConnect runs after every successful (re)connection; notifications
// sent while disconnected are lost, so callers re-check state here.
OnConnect func()
Rand func() float64
}
Config configures a Notifier.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier multiplexes one LISTEN connection to many subscribers and reconnects with jittered exponential backoff when the connection drops.
Click to show internal directories.
Click to hide internal directories.