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 ¶
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 (*Job) Run ¶
Run is the job function the app registers: RunOnce, with a log line when anything was deleted.
func (*Job) RunOnce ¶
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.