ttlworker

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ttlworker provides a background worker for purging expired data from the database.

Package ttlworker provides a background worker for purging expired data from the database.

Index

Constants

This section is empty.

Variables

View Source
var ErrNilStore = errors.New("ttlworker: store is required")

ErrNilStore is returned when New is called with a nil Store.

Functions

func DropOldPartitions

func DropOldPartitions(ctx context.Context, pool *pgxpool.Pool, st store.Store, cutoff time.Time, logger *slog.Logger) error

DropOldPartitions drops entire monthly partitions older than the cutoff date. This is much more efficient than row-by-row deletion for large partitions. Stray rows in the parent table (if any) are handled by the fallback DELETE queries. Returns an aggregated error if any table operations fail.

Types

type Options

type Options struct {
	// Store is the database store for executing TTL cleanup queries.
	Store store.Store
	// TTL is the time-to-live duration for logs, events, diffs, and artifact bundles.
	// Rows older than TTL will be deleted. Default: 30 days.
	TTL time.Duration
	// Interval is how often the worker runs. Default: 1 hour.
	Interval time.Duration
	// Logger is used for structured logging. If nil, a default logger is used.
	Logger *slog.Logger
	// DropPartitions enables dropping entire monthly partitions instead of
	// row-by-row deletion when the operator configures partitioned tables
	// out-of-band (e.g., on logs/events/artifact_bundles). Default: false.
	DropPartitions bool
}

Options configures the TTL worker.

type Worker

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

Worker is a background task that purges expired data from the database.

func New

func New(opts Options) (*Worker, error)

New constructs a new TTL worker. Returns ErrNilStore if opts.Store is nil.

func (*Worker) Interval

func (w *Worker) Interval() time.Duration

Interval returns how often the task should run.

func (*Worker) Name

func (w *Worker) Name() string

Name returns the task name for the scheduler.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run executes the TTL cleanup logic. Returns an aggregated error if any delete operations fail.

Jump to

Keyboard shortcuts

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