retention

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package retention is the hourly clean-up job: it hard-deletes messages older than the retention of their channel, deletes uploads that were never attached, removes blobs that no file refers to any more, and once a day sweeps the blob store for blobs that no row refers to at all.

Index

Constants

View Source
const (
	// Interval is how often the app runs the job.
	Interval = time.Hour
	// BatchSize is the number of messages or files deleted per transaction,
	// so the single writer is never held for long.
	BatchSize = 500
	// OrphanAge is how long an upload may stay unattached before it is
	// deleted.
	OrphanAge = 24 * time.Hour
	// OrphanSweepInterval is how often RunOnce walks the blob store for blobs
	// that no files row refers to.
	OrphanSweepInterval = 24 * time.Hour
	// OrphanBlobGrace is how recently a blob may have been written and still be
	// spared by that walk: an upload writes its blob before its row.
	OrphanBlobGrace = time.Hour
)

Job parameters.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blobs

type Blobs interface {
	// RemoveUnreferenced deletes the blobs of the given SHA-256 values that no
	// files row refers to, and returns how many it removed.
	RemoveUnreferenced(ctx context.Context, shas []string) (int, error)
	// SweepTmp deletes upload spool files older than maxAge.
	SweepTmp(maxAge time.Duration) (int, error)
	// SweepOrphanBlobs deletes the blobs no files row refers to, sparing those
	// modified within minAge, and returns how many it removed.
	SweepOrphanBlobs(ctx context.Context, minAge time.Duration) (int, error)
}

Blobs is the file store the job cleans up after.

type Job

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

Job is the retention and file clean-up job.

func New

func New(o Options) *Job

New returns a Job.

func (*Job) Run

func (j *Job) Run(ctx context.Context) error

Run is the job function the app registers: RunOnce, with a log line when anything was deleted.

func (*Job) RunOnce

func (j *Job) RunOnce(ctx context.Context) (Result, error)

RunOnce deletes expired messages, then orphaned uploads, then the blobs that lost their last file row, then stale spool files, then, once a day (the first run included, so it happens at startup), the blobs no row refers to. A failing step does not stop the later ones; the errors are joined.

type Options

type Options struct {
	// DB is the store; required.
	DB *store.DB
	// Settings supplies default_retention_days; required.
	Settings *settings.Store
	// Blobs removes blobs from disk; required.
	Blobs Blobs
	// Now is the clock; nil means time.Now. It should be the clock the store
	// uses.
	Now func() time.Time
	// Logger receives a summary of what a run deleted; nil discards it.
	Logger *slog.Logger
}

Options configure a Job.

type Result

type Result struct {
	// Messages are the expired messages hard-deleted.
	Messages int
	// Files are the unattached uploads deleted.
	Files int
	// Blobs are the blobs removed from disk.
	Blobs int
	// TmpFiles are the stale upload spool files removed.
	TmpFiles int
	// OrphanBlobs are the blobs found by the daily sweep that no files row
	// refers to, removed from disk. It is zero on the runs the sweep is not due.
	OrphanBlobs int
}

Result counts what one run deleted.

Jump to

Keyboard shortcuts

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