config

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 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"`
	DeadRetention          time.Duration `mapstructure:"dead_retention"`
	DiscardRetention       time.Duration `mapstructure:"discard_retention"`
	ClearPayloadOnComplete bool          `mapstructure:"clear_payload_on_complete"`
	PublishTimeout         time.Duration `mapstructure:"publish_timeout"`
	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 WithClearPayloadOnComplete added in v1.1.0

func WithClearPayloadOnComplete(enabled bool) Option

WithClearPayloadOnComplete atomically empties payload and headers when a row becomes published or discarded. Dead rows retain data for inspection/replay. Other columns (including LastError) are retained; callers must sanitize them.

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 WithDeadRetention added in v1.1.0

func WithDeadRetention(ttl time.Duration) Option

WithDeadRetention enables deletion of dead rows after this terminal-state age. Disabled by default. Requires WithCleanupInterval.

func WithDiscardRetention added in v1.1.0

func WithDiscardRetention(ttl time.Duration) Option

WithDiscardRetention enables deletion of discarded rows after this age. Disabled by default. Requires WithCleanupInterval.

func WithFatal added in v1.1.1

func WithFatal(f func(error) bool) Option

WithFatal sets the classifier consulted on every Publish error and every internal relay/cleaner error (claim, renew, completion, cleanup) while the context is live. When it returns true, Run stops and returns the error; the claimed batch is not completed, retried or dead-lettered and is re-claimed after its lease expires. Abort outcomes and recovered panics are always fatal. Default: nothing else is fatal.

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 WithPublishTimeout added in v1.1.0

func WithPublishTimeout(d time.Duration) Option

WithPublishTimeout limits each Publish call. Zero disables the timeout. Publishers must honor the supplied context; a timeout cannot undo a side effect.

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
	DeadRetention          time.Duration
	DiscardRetention       time.Duration
	ClearPayloadOnComplete bool
	PublishTimeout         time.Duration
	CleanupInterval        time.Duration
	Ordered                bool
	Notify                 bool
	ListenPool             *pgxpool.Pool
	Fatal                  func(error) bool
	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