Help us shape the future of Go! Take the 2026 Go Developer Survey

retention

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package retention removes what Pando keeps only for a while: old deploys, scans, sessions, notifications, idempotency keys, sign-in flows, the event outbox, and what deleted apps left behind (issue #72, R-224).

One leader job, hourly, deleting a batch at a time. Each table's window is a setting with a documented default; what each delete never removes — revisions (R-152), the audit log (R-027), rollback targets (R-157) — is in the state store's queries rather than here, so no setting can reach it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Store    Store
	Outbox   Outbox
	Settings Settings
	Clock    clock.Clock
	Logger   *zap.Logger

	// Every is how often it runs. An hour when zero.
	Every time.Duration
}

Job removes old rows, hourly. A leader job: once per install.

func (*Job) Pass

func (j *Job) Pass(ctx context.Context) map[string]int64

Pass is one run over every table, and returns how many rows went from each.

func (*Job) Run

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

Run removes old rows until ctx ends, starting at once.

type Outbox

type Outbox interface {
	Prune(ctx context.Context, before time.Time, limit int) (int64, error)
}

Outbox is the event outbox's prune.

type Settings

type Settings struct {
	// DeploymentsPerApp is how many of an app's newest deploys are kept
	// [P]: 50, what an app's deploy list shows. Older ones go, except one in
	// flight or waiting for approval and the newest successful deploy of
	// each revision the app ever pinned.
	DeploymentsPerApp int

	// Scans is how long a scan is kept [P]: 90 days. The newest scan of
	// each revision is kept however old.
	Scans time.Duration

	// Sessions is how long an expired or revoked session is kept [P]: 30
	// days.
	Sessions time.Duration

	// IdempotencyKeys is how long a key's answer is replayed [P]: a day
	// (migration 000011).
	IdempotencyKeys time.Duration

	// SSOFlows is how long a sign-in flow is kept after it expired [P]: a
	// day, so a person arriving late at a failed sign-in is told why.
	SSOFlows time.Duration

	// Events is how long the outbox keeps an event with nothing left to
	// deliver, and its deliveries and their attempts [P]: 30 days
	// (subscription.Retention).
	Events time.Duration

	// DeletedApps is how long a deleted app's detection and backup-attempt
	// record are kept [P]: 30 days.
	DeletedApps time.Duration

	// Batch is how many rows one delete removes. 1,000 when zero.
	Batch int
}

Settings is how long each kind of row is kept. A zero field is its default.

func (Settings) Defaults

func (s Settings) Defaults() Settings

Defaults fills in every zero field.

type Store

type Store interface {
	Deployments(ctx context.Context, keepPerApp, limit int) (int64, error)
	DeletedApps(ctx context.Context, before time.Time, limit int) (int64, error)
	Scans(ctx context.Context, before time.Time, limit int) (int64, error)
	Sessions(ctx context.Context, before time.Time, limit int) (int64, error)
	Notifications(ctx context.Context, now time.Time, limit int) (int64, error)
	IdempotencyKeys(ctx context.Context, before time.Time, limit int) (int64, error)
	SSOFlows(ctx context.Context, before, now time.Time, limit int) (int64, error)
}

Store is the slice of state.Retention and state.Events the job deletes with.

Jump to

Keyboard shortcuts

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