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

notifyqueue

package
v1.118.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package notifyqueue is the durable delivery queue: the PostgreSQL implementation of notification.QueueStore over the notifications table, and the LISTEN side of the pg_notify wakeup it fires on every enqueue.

The store and the listener are two halves of one mechanism — the store NOTIFYs on NotifyChannel, the listener LISTENs on it and wakes the send worker — so they share this package and the channel name that binds them.

Index

Constants

View Source
const NotifyChannel = "notifications"

NotifyChannel is the pg_notify channel that wakes the send worker when a row is enqueued. Producers fire it best-effort; the worker also polls.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

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

Listener is the LISTEN side of the queue's LISTEN/NOTIFY adapter. Enqueue fires NOTIFY; this goroutine receives it and wakes the worker so immediate notifications go out without waiting for the poll interval.

func NewListener

func NewListener(dsn string, notifiers ...notifier) *Listener

NewListener constructs a Listener for the supplied DSN. It does not connect until Start is called.

func (*Listener) Start

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

Start opens the LISTEN connection and spawns the receive goroutine. An error means delivery latency degrades to the worker's poll interval; the caller decides whether that is fatal.

func (*Listener) Stop

func (l *Listener) Stop()

Stop closes the LISTEN connection and waits for the receive goroutine.

type PostgresStore

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

PostgresStore implements notification.QueueStore backed by the notifications table.

func NewPostgresStore

func NewPostgresStore(db *sql.DB) *PostgresStore

NewPostgresStore creates a PostgreSQL-backed notification queue.

func (*PostgresStore) ClaimDigest

func (s *PostgresStore) ClaimDigest(ctx context.Context, lease time.Duration) ([]notification.Notification, error)

ClaimDigest claims all due digest rows for the recipient with the oldest due digest row. Concurrent workers racing for the same recipient are safe: the loser's UPDATE matches zero rows and reports notification.ErrNoWork.

func (*PostgresStore) ClaimImmediate

func (s *PostgresStore) ClaimImmediate(ctx context.Context, lease time.Duration) (*notification.Notification, error)

ClaimImmediate claims the next due non-digest row.

func (*PostgresStore) Count

func (s *PostgresStore) Count(ctx context.Context, filter notification.HistoryFilter) (int, error)

Count returns how many rows match the filter, ignoring its paging fields.

func (*PostgresStore) CountsByStatus

func (s *PostgresStore) CountsByStatus(ctx context.Context, filter notification.HistoryFilter) (map[string]int, error)

CountsByStatus returns the per-status row counts for the filter. Statuses with no rows are absent from the map; callers render a zero for them.

func (*PostgresStore) Enqueue

Enqueue inserts a pending notification row and fires a best-effort pg_notify so a listening worker wakes without waiting for the next poll.

func (*PostgresStore) Fail

func (s *PostgresStore) Fail(ctx context.Context, ids []int64, sendErr string) error

Fail marks claimed rows permanently failed.

func (*PostgresStore) List

List returns one page of notification history, newest first.

func (*PostgresStore) MarkSent

func (s *PostgresStore) MarkSent(ctx context.Context, ids []int64) error

MarkSent transitions claimed rows to sent.

func (*PostgresStore) PurgeOld

func (s *PostgresStore) PurgeOld(ctx context.Context, resolvedRetention, pendingTTL time.Duration) (int64, error)

PurgeOld deletes resolved rows past retention and unresolved rows past their delivery-relevance window.

func (*PostgresStore) Retry

func (s *PostgresStore) Retry(ctx context.Context, ids []int64, sendErr string, backoff time.Duration) error

Retry returns claimed rows to pending, scheduled after the backoff.

Jump to

Keyboard shortcuts

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