Help us shape the future of Go! Take the 2026 Go Developer Survey

pgnotify

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pgnotify runs one shared PostgreSQL LISTEN connection and dispatches notifications to per-channel reload functions. It owns the pinned connection, dispatch, reconnect, and health; it knows nothing about what any cache holds.

Index

Constants

View Source
const AppName = "memory-config-listener"

AppName tags the listener's backend in pg_stat_activity so operators can find (and tests can terminate) exactly this connection.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener holds the dedicated LISTEN connection and its channel registrations.

func New

func New(db *sql.DB, logger *slog.Logger, opts ...Option) *Listener

New returns a Listener over db's pool. Register channels, then Start.

func (*Listener) Healthy

func (l *Listener) Healthy() bool

Healthy reports whether the listener currently holds a live listening connection.

func (*Listener) Register

func (l *Listener) Register(channel string, reload ReloadFunc)

Register binds a reload function to a channel. Call before Start; the set is read when the connection is (re)established.

func (*Listener) Start

func (l *Listener) Start(ctx context.Context) error

Start establishes LISTEN, then runs the dispatch/reconnect loop in the background. It returns once the first LISTEN is established (nil) or the first attempt fails — so a caller can guarantee LISTEN precedes any initial load.

func (*Listener) Stop

func (l *Listener) Stop()

Stop cancels the loop and waits for the pinned connection to be released.

type Option

type Option func(*Listener)

Option tunes a Listener at construction.

func WithBackoff

func WithBackoff(base, max time.Duration) Option

WithBackoff sets the reconnect backoff ramp (base doubles up to max).

type ReloadFunc

type ReloadFunc func(ctx context.Context) error

ReloadFunc reloads a cache from the database. It MUST be idempotent: the listener calls it on every reconnect and a replica may get its own notification, so a redundant reload has to be a no-op.

Jump to

Keyboard shortcuts

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