scanjobs

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package scanjobs runs long administrative work, such as schema scans, on the Scan lane of the execution bus, off the request path: a request starts a job and polls it, so a slow database ties up neither the request nor the service.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("scanjobs: too many jobs queued; retry later")

ErrBusy is returned when the queue is full.

Functions

This section is empty.

Types

type Job

type Job[T any] struct {
	ID string
	// Label says what the job works on (a datasource name).
	Label  string
	State  State
	Result T
	Err    string
}

Job is a snapshot of one job.

type Options

type Options struct {
	// Bus runs the jobs on its Scan lane, whose limits then replace Workers
	// and Queue; without one the pool has a lane of its own.
	Bus     *bus.Bus
	Workers int           // concurrent jobs (default 2)
	Queue   int           // jobs waiting for a worker (default 8)
	Timeout time.Duration // per job (default 5m)
	// Keep is how long a finished job stays readable (default 10m).
	Keep time.Duration
}

Options size the pool.

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool runs jobs that produce a T.

func New

func New[T any](opts Options) *Pool[T]

New returns a pool; Close stops it.

func (*Pool[T]) Cancel

func (p *Pool[T]) Cancel(id string) (Job[T], bool)

Cancel stops job id: a pending job never runs, a running one has its context canceled.

func (*Pool[T]) Close

func (p *Pool[T]) Close()

Close cancels every job and waits for them.

func (*Pool[T]) Get

func (p *Pool[T]) Get(id string) (Job[T], bool)

Get returns the job id, if it exists and has not expired.

func (*Pool[T]) Start

func (p *Pool[T]) Start(label string, run func(context.Context) (T, error)) (Job[T], error)

Start queues run, labeled label, and returns the pending job.

type State

type State string

State is where a job is in its life.

const (
	Pending  State = "PENDING"
	Running  State = "RUNNING"
	Done     State = "DONE"
	Failed   State = "FAILED"
	Canceled State = "CANCELED"
)

Jump to

Keyboard shortcuts

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