engine

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package engine implements the outbox background machinery: the store (enqueue/claim/mark/cleanup queries) and the relay and cleaner workers.

Index

Constants

View Source
const NotifyChannel = "outbox_messages"

NotifyChannel is the fixed LISTEN/NOTIFY channel (matches the migration trigger). It cannot be parameterized; cross-schema wake-ups are harmless because SKIP LOCKED deduplicates claims.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleaner

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

Cleaner deletes terminal rows according to their opt-in retention windows.

func NewCleaner

func NewCleaner(s Store, set config.Settings) *Cleaner

NewCleaner builds a Cleaner.

func (*Cleaner) Run

func (c *Cleaner) Run(ctx context.Context) error

Run is a no-op unless at least one retention window and the cleanup interval are set. Otherwise it blocks until ctx is cancelled and returns nil, or returns the first fatal error (see isFatal), including a recovered panic.

type Relay

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

Relay claims ready rows, publishes them, and records the outcome.

func NewRelay

func NewRelay(s Store, pub port.Publisher, set config.Settings) *Relay

NewRelay builds a Relay.

func (*Relay) Run

func (r *Relay) Run(ctx context.Context) error

Run starts the relay: set.Concurrency worker goroutines plus an optional LISTEN/NOTIFY listener. It blocks until ctx is cancelled and returns nil, or until a fatal error (see isFatal) stops every worker; then it returns that error. Panics in any relay goroutine are recovered as *port.PanicError.

type Store

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

Store runs the outbox SQL. The relay/cleaner queries use exec (must not be tx-bound); enqueue uses enq (joins the caller's business tx). pool is optional and only LISTEN/NOTIFY needs it.

func NewStore

func NewStore(exec, enq port.Executor, pool *pgxpool.Pool, schema string) Store

NewStore builds a Store. schema is assumed already validated.

func (Store) Enqueue

func (s Store) Enqueue(ctx context.Context, msgs []message.Message) error

Enqueue inserts messages using the transactional Executor, so the rows land in the caller's business transaction.

func (Store) Requeue added in v1.1.0

func (s Store) Requeue(ctx context.Context, id string) (bool, error)

Requeue uses the caller's transactional executor. A locked row cannot be removed by cleanup concurrently. Notifications become visible on commit.

func (Store) Table

func (s Store) Table() string

Table returns the schema-qualified table identifier.

Jump to

Keyboard shortcuts

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