outboxpostgres

package
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package outboxpostgres provides a supported-adapter Postgres transactional outbox.

Use New with a ports.DatabasePool and Options when async workers need an async.Store backed by Postgres. Store preserves enqueue, lease, complete, retry/dead-letter, stuck-lease recovery, table-name validation, and readiness health behavior.

Events must pass validation before enqueue. Failure messages are kept low-secret and lease completion requires the current lease owner so stale workers cannot complete another worker's job.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEventNotFound reports that an outbox event was not found for the current lease owner.
	ErrEventNotFound = errors.New("outbox event not found")
	// ErrInvalidEvent reports that an outbox event is missing required fields.
	ErrInvalidEvent = errors.New("invalid outbox event")
	// ErrInvalidTable reports that a configured table name is not a safe SQL identifier.
	ErrInvalidTable = errors.New("invalid outbox table")
	// ErrStoreNotConfigured reports that the store or pool was not configured.
	ErrStoreNotConfigured = errors.New("outbox postgres store not configured")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	ID       string
	TenantID string
	Type     string
	Payload  []byte
	NextAt   time.Time
}

Event is an event to enqueue into the transactional outbox.

type Options

type Options struct {
	Table         string
	Clock         func() time.Time
	LeaseOwner    string
	LeaseDuration time.Duration
	RetryDelay    time.Duration
	MaxRetryDelay time.Duration
	MaxAttempts   int
}

Options configures the Postgres outbox store.

type Store

type Store struct {
	Pool ports.DatabasePool
	// contains filtered or unexported fields
}

Store persists and leases outbox events in Postgres.

func New

func New(pool ports.DatabasePool, opts Options) *Store

New creates a Postgres-backed outbox store.

func (*Store) Complete

func (s *Store) Complete(ctx context.Context, id string) error

Complete marks a leased event as succeeded.

func (*Store) Enqueue

func (s *Store) Enqueue(ctx context.Context, event Event) error

Enqueue inserts an event into the outbox.

func (*Store) Fail

func (s *Store) Fail(ctx context.Context, id string, _ string) error

Fail records a retryable failure or dead-letters the event after MaxAttempts.

func (*Store) HealthChecker

func (s *Store) HealthChecker() ports.HealthChecker

HealthChecker returns a Postgres outbox dependency health checker.

func (*Store) Lease

func (s *Store) Lease(ctx context.Context, limit int) ([]async.Job, error)

Lease leases due outbox events for async worker execution.

Jump to

Keyboard shortcuts

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