housekeeping

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package housekeeping trims persisted job history (Job / JobTask / JobTaskEvent) so the tables that receive hub "event" envelopes cannot grow without bound. It is a job target, not a background loop: an operator schedules or triggers "housekeeping" the same way as a sync target; nothing runs it on its own.

Index

Constants

View Source
const DefaultKeep = 50

DefaultKeep is how many newest finished Jobs Trim retains when the caller passes Keep < 1. Matches GET /api/jobs's list cap.

Variables

This section is empty.

Functions

func EffectiveKeep

func EffectiveKeep(n int) int

EffectiveKeep maps a Settings.JobHistoryKeep value onto the number Trim will actually retain. 0/negative is treated as DefaultKeep so an unset column cannot wipe history on the first run.

Types

type Options

type Options struct {
	// Keep is the number of newest finished Jobs to retain, plus their
	// JobTasks and JobTaskEvents. Values < 1 mean DefaultKeep.
	Keep int
	// ProtectJobIDs are never deleted, even if they are finished and
	// outside the Keep window - used to spare the in-flight housekeeping
	// job itself (already unfinished, but listed here as belt-and-braces).
	ProtectJobIDs []uint
}

Options controls one Trim run.

type Result

type Result struct {
	JobsDeleted   int64
	TasksDeleted  int64
	EventsDeleted int64
}

Result is how many rows Trim deleted. EventsDeleted includes both events belonging to deleted jobs and orphan rows (job_task_id IS NULL).

func Trim

func Trim(db *gorm.DB, opt Options) (Result, error)

Trim deletes finished Jobs older than the Keep newest, along with their JobTasks and JobTaskEvents, and any orphan JobTaskEvent rows (no owning JobTask - ad hoc --job runs). Unfinished jobs are never deleted.

Jump to

Keyboard shortcuts

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