maintenance

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package maintenance runs the leader-only background services and the cancel poller.

Index

Constants

View Source
const (
	DefaultSchedulerInterval = time.Second
	DefaultCleanerInterval   = 30 * time.Second
	DefaultDepthInterval     = 15 * time.Second
	DefaultPeriodicInterval  = time.Second
	DefaultBatch             = 1000

	RunTimeout     = 2 * time.Minute
	ReindexTimeout = time.Hour
)
View Source
const DefaultTickRetention = 7 * 24 * time.Hour
View Source
const PeriodicGrace = 15 * time.Second

Variables

This section is empty.

Functions

func RescueCompletion

func RescueCompletion(row *job.Row, now time.Time, retry func(*job.Row, time.Time) time.Time) job.Completion

func RunAll

func RunAll(ctx context.Context, services ...Service)

RunAll runs services concurrently and returns when all have stopped.

Types

type Base

type Base struct {
	Store   job.MaintenanceStore
	Clock   clock.Clock
	Logger  *slog.Logger
	Observe func(service string, rows int, at time.Time)
}

type CancelPoller

type CancelPoller struct {
	Store    job.CancelPoller
	Clock    clock.Clock
	Logger   *slog.Logger
	Interval time.Duration
	Running  func() []int64
	OnCancel func(id int64)
}

CancelPoller finds cancel requests for this client's running jobs by polling.

func (*CancelPoller) Poll

func (p *CancelPoller) Poll(ctx context.Context)

func (*CancelPoller) Run

func (p *CancelPoller) Run(ctx context.Context) error

type Cleaner

type Cleaner struct {
	Base
	Interval      time.Duration
	Retention     map[job.State]time.Duration
	TickRetention time.Duration
	Batch         int
}

Cleaner deletes finalized jobs older than their retention.

func (*Cleaner) Run

func (c *Cleaner) Run(ctx context.Context) error

type DepthSampler

type DepthSampler struct {
	Base
	Interval time.Duration
	OnDepths func([]job.QueueDepth)
}

DepthSampler samples the queue depth per state for metrics.

func (*DepthSampler) Run

func (d *DepthSampler) Run(ctx context.Context) error

type Periodic

type Periodic struct {
	Base
	Jobs       []PeriodicJob
	Interval   time.Duration
	OnSkipped  func(name string, n int)
	OnEnqueued func(name string, tick time.Time)
}

Periodic enqueues each periodic job once per tick.

func (*Periodic) Run

func (p *Periodic) Run(ctx context.Context) error

type PeriodicJob

type PeriodicJob struct {
	Name       string
	Schedule   schedule.Schedule
	CatchUp    time.Duration
	RunOnStart bool
	Build      func(tick time.Time) (job.InsertParams, error)
}

type Reindexer

type Reindexer struct {
	Base
	Interval time.Duration
}

Reindexer rebuilds the queue indexes every Interval.

func (*Reindexer) Run

func (r *Reindexer) Run(ctx context.Context) error

type Rescuer

type Rescuer struct {
	Base
	Interval   time.Duration
	StuckAfter time.Duration
	Retry      func(row *job.Row, now time.Time) time.Time
	Batch      int
	OnRescued  func(n int)
}

Rescuer returns running jobs without a heartbeat to retryable, or discards them when attempts run out.

func (*Rescuer) Run

func (r *Rescuer) Run(ctx context.Context) error

type Scheduler

type Scheduler struct {
	Base
	Interval time.Duration
	Batch    int
}

Scheduler moves scheduled and retryable jobs to available when they are due.

func (*Scheduler) Run

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

type Service

type Service interface {
	Run(ctx context.Context) error
}

Service is a long-running maintenance loop.

Jump to

Keyboard shortcuts

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