notifyworker

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: 11 Imported by: 0

Documentation

Overview

Package notifyworker drains the notification queue: it claims due rows under a lease, renders them, delivers them over SMTP, and resolves each batch to sent, retried, or failed.

It owns the delivery policy — the deliverability gate, the retry budget and its backoff, and the retention purge that bounds the table — and holds the rendering and transport layers behind the two collaborators in Config.

Index

Constants

View Source
const (
	// DefaultPollEvery is the fallback poll interval when LISTEN/NOTIFY does
	// not wake the worker.
	DefaultPollEvery = 30 * time.Second
	// DefaultLease bounds one delivery attempt; an expired lease returns the
	// row to claimable state for crash recovery.
	DefaultLease = 2 * time.Minute
	// DefaultMaxAttempts is the delivery attempt budget per row.
	DefaultMaxAttempts = 5

	// DefaultResolvedRetention keeps sent/failed rows for operator
	// inspection before the purge removes them.
	DefaultResolvedRetention = 30 * 24 * time.Hour
	// DefaultPendingTTL bounds how long an undelivered row stays relevant.
	// Beyond it the event is stale (nobody wants a share email from last
	// month when SMTP is finally configured) and the purge drops it.
	DefaultPendingTTL = 7 * 24 * time.Hour
)

Worker defaults.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Queue    notification.QueueStore
	Settings smtp.SettingsStore
	Renderer *notifyrender.Renderer
	Sender   notifysend.Sender
	// PollEvery, Lease, and MaxAttempts default to the package constants
	// when zero.
	PollEvery   time.Duration
	Lease       time.Duration
	MaxAttempts int
}

Config configures the send worker.

type Worker

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

Worker drains the notification queue: it claims due rows, renders branded emails, and delivers them over SMTP. It follows the indexjobs worker shape (poll ticker + LISTEN/NOTIFY wakeup, lease-based claiming, retry with exponential backoff). When SMTP is unconfigured or disabled the worker leaves rows pending without burning delivery attempts.

func New

func New(cfg Config) *Worker

New creates a send worker, applying defaults for zero config values.

func (*Worker) Notify

func (w *Worker) Notify()

Notify wakes the worker without waiting for the next poll tick. Safe to call from any goroutine; a flurry of calls coalesces into one wakeup.

func (*Worker) Start

func (w *Worker) Start(_ context.Context)

Start launches the worker loop. Idempotent.

func (*Worker) Stop

func (w *Worker) Stop()

Stop terminates the worker loop and waits for in-flight work. Idempotent. An abandoned claimed row is safe: its lease expires and it is reclaimed.

Jump to

Keyboard shortcuts

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