maintenance

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleaner

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

Cleaner periodically deletes finalized tasks after their retention period. This helps keep the asynqpg_tasks table small and performant.

func NewCleaner

func NewCleaner(repo cleanerRepo, config CleanerConfig) *Cleaner

NewCleaner creates a new Cleaner service.

func (*Cleaner) Name

func (c *Cleaner) Name() string

func (*Cleaner) Start

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

func (*Cleaner) Stop

func (c *Cleaner) Stop()

type CleanerConfig

type CleanerConfig struct {
	// CompletedRetention is how long to keep completed tasks.
	// Default: 24 hours.
	CompletedRetention time.Duration

	// FailedRetention is how long to keep failed (discarded) tasks.
	// Default: 7 days.
	FailedRetention time.Duration

	// CancelledRetention is how long to keep cancelled tasks.
	// Default: 24 hours.
	CancelledRetention time.Duration

	// Interval is the frequency of cleanup runs.
	// Default: 30 seconds.
	Interval time.Duration

	// BatchSize is the maximum number of tasks to delete in one iteration.
	// Default: 1000.
	BatchSize int

	// Logger for the cleaner.
	Logger *slog.Logger
}

CleanerConfig configures the task cleaner service.

type Maintainer

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

Maintainer manages multiple maintenance services. It starts/stops all services together and is typically controlled by the leadership elector - only the leader runs maintenance services.

func NewMaintainer

func NewMaintainer(logger *slog.Logger, services ...Service) *Maintainer

NewMaintainer creates a new Maintainer with the given services.

func (*Maintainer) IsStarted

func (m *Maintainer) IsStarted() bool

IsStarted returns whether the maintainer is currently running.

func (*Maintainer) Start

func (m *Maintainer) Start(ctx context.Context) error

Start starts all maintenance services. Services run until Stop is called or the provided context is cancelled.

func (*Maintainer) Stop

func (m *Maintainer) Stop()

Stop stops all maintenance services gracefully.

type Rescuer

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

Rescuer periodically rescues stuck tasks that have been running too long. A task is considered stuck if: - Status is 'running' - attempted_at + RescueAfter < now()

For stuck tasks: - If attempts_left > 0: retry with exponential backoff - If attempts_left == 0: discard (mark as failed)

func NewRescuer

func NewRescuer(repo rescuerRepo, config RescuerConfig) *Rescuer

NewRescuer creates a new Rescuer service.

func (*Rescuer) Name

func (r *Rescuer) Name() string

func (*Rescuer) Start

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

func (*Rescuer) Stop

func (r *Rescuer) Stop()

type RescuerConfig

type RescuerConfig struct {
	// RescueAfter is the duration after which a running task is considered stuck.
	// Default: 1 hour.
	RescueAfter time.Duration

	// Interval is the frequency of rescue checks.
	// Default: 30 seconds.
	Interval time.Duration

	// BatchSize is the maximum number of tasks to rescue in one iteration.
	// Default: 1000.
	BatchSize int

	// RetryPolicy determines retry delays for rescued tasks.
	// If nil, DefaultRetryPolicy is used.
	RetryPolicy asynqpg.RetryPolicy

	// Logger for the rescuer.
	Logger *slog.Logger
}

RescuerConfig configures the task rescuer service.

type Service

type Service interface {
	// Start starts the service. It should return immediately after starting
	// background goroutines. The service should stop when ctx is cancelled.
	Start(ctx context.Context) error

	// Stop stops the service gracefully.
	Stop()

	// Name returns the service name for logging.
	Name() string
}

Service represents a background maintenance service.

Jump to

Keyboard shortcuts

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