config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config holds the outbox runtime settings, the functional options that build them, and the declarative Config struct (mapstructure/validate/default tags) for loading from files or environment.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSchema = errors.New("outbox: invalid schema identifier")

ErrInvalidSchema is returned when the schema is not a valid identifier.

Functions

func ValidSchema

func ValidSchema(s string) bool

ValidSchema reports whether s is a safe schema identifier.

Types

type Config

type Config struct {
	Schema          string        `mapstructure:"schema" default:"public"`
	PollInterval    time.Duration `mapstructure:"poll_interval" default:"1s"`
	BatchSize       int           `mapstructure:"batch_size" default:"100"`
	LeaseDuration   time.Duration `mapstructure:"lease_duration" default:"30s"`
	Concurrency     int           `mapstructure:"concurrency" default:"1"`
	MaxAttempts     int           `mapstructure:"max_attempts" default:"10"`
	Retention       time.Duration `mapstructure:"retention"`
	CleanupInterval time.Duration `mapstructure:"cleanup_interval"`
	Ordered         bool          `mapstructure:"ordered"`
	// DisableNotify turns LISTEN/NOTIFY off (poll-only). The zero value keeps
	// NOTIFY enabled, so a hand-built Config does not silently disable it.
	DisableNotify bool `mapstructure:"disable_notify"`
}

Config is the declarative outbox configuration, loaded from a file or environment (mapstructure) with validation and defaults. It mirrors the functional options; the logger is injected separately via WithLogger because it is a runtime dependency, not configuration data.

type Option

type Option func(*Settings)

Option configures Settings.

func WithBatchSize

func WithBatchSize(n int) Option

WithBatchSize sets the max rows claimed per cycle (default 100).

func WithCleanupInterval

func WithCleanupInterval(d time.Duration) Option

WithCleanupInterval sets how often the cleaner runs (default off).

func WithCodec

func WithCodec(c port.Codec) Option

WithCodec sets the codec used by EnqueueValue.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency sets the number of relay worker goroutines (default 1).

func WithConfig

func WithConfig(c Config) Option

WithConfig applies a declarative Config onto the settings. Apply it before any narrower Option you want to win.

func WithHooks

func WithHooks(h port.Hooks) Option

WithHooks sets the observability hooks (default NoopHooks).

func WithInstanceID

func WithInstanceID(id string) Option

WithInstanceID sets the lease owner id (locked_by). Required before Run. Must be unique and stable per process (e.g. the Kubernetes pod name).

func WithLeaseDuration

func WithLeaseDuration(d time.Duration) Option

WithLeaseDuration sets how long a claimed row stays locked (default 30s).

func WithListenPool

func WithListenPool(p *pgxpool.Pool) Option

WithListenPool supplies the *pgxpool.Pool used for LISTEN/NOTIFY wake-ups. Without it (and unless the relay executor is itself a *pgxpool.Pool), the relay falls back to polling only.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger injects the slog logger from outside (default a no-op logger that discards everything).

func WithMaxAttempts

func WithMaxAttempts(n int) Option

WithMaxAttempts sets the default attempt ceiling before dead-lettering (default 10).

func WithOrdered

func WithOrdered(v bool) Option

WithOrdered enables strict per-partition_key ordering.

func WithPollInterval

func WithPollInterval(d time.Duration) Option

WithPollInterval sets how often the relay polls when idle (default 1s).

func WithRetention

func WithRetention(ttl time.Duration) Option

WithRetention enables cleanup of published rows older than ttl. The cleaner also needs WithCleanupInterval to run.

func WithRetryBackoff

func WithRetryBackoff(b backoff.Backoff) Option

WithRetryBackoff overrides the retry backoff (default backoff.Default).

func WithSchema

func WithSchema(schema string) Option

WithSchema sets the Postgres schema the table lives in (default "public").

func WithoutNotify

func WithoutNotify() Option

WithoutNotify disables LISTEN/NOTIFY wake-ups (poll-only).

type Settings

type Settings struct {
	InstanceID      string
	Schema          string
	PollInterval    time.Duration
	BatchSize       int
	LeaseDuration   time.Duration
	Concurrency     int
	MaxAttempts     int
	Backoff         backoff.Backoff
	Retention       time.Duration
	CleanupInterval time.Duration
	Ordered         bool
	Notify          bool
	ListenPool      *pgxpool.Pool
	Hooks           port.Hooks
	Codec           port.Codec
	Logger          *slog.Logger
}

Settings is the resolved runtime configuration the engine reads. Build it with Default plus Options, or from a declarative Config via WithConfig.

func Default

func Default() Settings

Default returns the baseline settings before any Option is applied.

func Resolve

func Resolve(opts ...Option) Settings

Resolve applies opts to a fresh Default and normalizes bounds. Every non-positive numeric/duration field and an empty schema fall back to the Default value, so even a zero-value Config passed via WithConfig yields a valid, runnable Settings.

Jump to

Keyboard shortcuts

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