outbox

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package outbox is the durable queue between smtp.Send and the relay: gopherex/pg-outbox over the service's store. Enqueue joins the caller's transaction; every replica runs the relay, which hands claimed deliveries to the Publisher (the mailer) and retries or dead-letters by its answer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Concurrency bounds deliveries in flight per replica.
	Concurrency int64 `json:"concurrency" schemapb:"default=4;gte=1;lte=64"`
	// MaxAttempts before a delivery is dead.
	MaxAttempts int64 `json:"max_attempts" schemapb:"default=10;gte=1;lte=100"`
	// RetryMax bounds the backoff between attempts (1s doubling to it).
	RetryMax time.Duration `json:"retry_max" schemapb:"default=10m"`
	// Retention of sent deliveries; DeadRetention of dead ones.
	Retention     time.Duration `json:"retention"      schemapb:"default=72h"`
	DeadRetention time.Duration `json:"dead_retention" schemapb:"default=168h"`
}

Config of the queue.

type Delivery

type Delivery struct {
	ID      string       `json:"id"`
	Account string       `json:"account"`
	From    string       `json:"from"`
	Caller  string       `json:"caller,omitempty"`
	Message mail.Message `json:"message"`
}

Delivery is one queued mail: the message as validated, the account it goes through and who asked.

type Outbox

type Outbox struct {
	deps.Component
	// contains filtered or unexported fields
}

Outbox is the component owning the relay.

func New

func New(parent deps.Scope, cfg Config, st deps.Dependency[*store.Store], pub Publisher, instance string) *Outbox

New creates the queue under parent; the relay runs once the store is provided.

func (*Outbox) Enqueue

func (o *Outbox) Enqueue(ctx context.Context, d Delivery) error

Enqueue stores d for delivery, atomically with the caller's transaction.

func (*Outbox) Requeue added in v0.2.0

func (o *Outbox) Requeue(ctx context.Context, id string) (bool, error)

Requeue returns a dead delivery to the queue with its attempts reset; false: no dead delivery has that id.

func (*Outbox) Settings added in v0.2.0

func (o *Outbox) Settings() Config

Settings the queue runs with, for the console.

type Publisher

type Publisher interface {
	Deliver(ctx context.Context, d Delivery, attempt int) error
	// Dead is told once a delivery exhausted its attempts.
	Dead(ctx context.Context, d Delivery, attempts int, lastError string)
}

Publisher delivers one claimed delivery; see pg-outbox's outcomes (Permanent, Discard) for how its error is read.

Jump to

Keyboard shortcuts

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