cleanup

package
v0.12.1 Latest Latest
Warning

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

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

Documentation

Overview

Package cleanup runs the scheduled, in-process pruning of stale rows from the slack_messages table. The scheduler runs one cleanup immediately on start, then once every Interval, until its context is cancelled.

Index

Constants

View Source
const Interval = 24 * time.Hour

Interval is the fixed cadence between cleanup ticks. 24h is conservative enough that a transient DB error has nearly a full day to clear before the next attempt.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

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

Scheduler periodically deletes slack_messages rows older than ttl.

func NewScheduler

func NewScheduler(deleter StaleMessageDeleter, ttl, interval time.Duration, logger *slog.Logger) *Scheduler

NewScheduler constructs a Scheduler. ttl is the maximum age a row may reach before becoming eligible for deletion; interval is the cadence between cleanup attempts (use cleanup.Interval in production).

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

Run drives one cleanup immediately, then one per interval, until ctx is cancelled. Errors from the deleter are logged and swallowed — the next tick retries. Always returns nil (the signature stays error-returning so callers can compose it with other long-running goroutines without special-casing).

func (*Scheduler) SetNowFunc

func (s *Scheduler) SetNowFunc(now func() time.Time)

SetNowFunc overrides the clock used to compute cutoff timestamps. Tests only — production code uses the default time.Now.

type StaleMessageDeleter

type StaleMessageDeleter interface {
	DeleteStaleBefore(ctx context.Context, cutoff time.Time) (int64, error)
}

StaleMessageDeleter is the slice of the store API the scheduler needs. Declared here, in the consumer package, so the store stays unaware of how callers use it.

Jump to

Keyboard shortcuts

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