jobs

package
v0.68.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DuplicateJobID = "-1"
	UnqueuedJobID  = "-2"
)

Variables

View Source
var (
	ErrContextHasNoJob       = errors.New("context has no Job")
	ErrJobTimeout            = errors.New("timed out waiting for job(s)")
	ErrNoQueueSpecified      = errors.New("this job does not specify a queue. please specify a queue")
	ErrJobExceededDeadline   = errors.New("the job did not complete before its deadline")
	ErrJobExceededMaxRetries = errors.New("the job has exceeded the maximum number of retries")
)

Functions

func FingerprintJob

func FingerprintJob(j *Job) (err error)

FingerprintJob fingerprints jobs as an md5 hash of its queue combined with its JSON-serialized payload

func WithJobContext added in v0.67.0

func WithJobContext(ctx context.Context, job *Job) context.Context

WithJobContext adds a job to the provided context

Types

type Job

type Job struct {
	ID          int64          `db:"id"`
	Fingerprint string         `db:"fingerprint"` // A md5 sum of the job's queue + payload, affects job deduplication
	Status      string         `db:"status"`      // The status of the job
	Queue       string         `db:"queue"`       // The queue the job is on
	Payload     map[string]any `db:"payload"`     // JSON job payload for more complex jobs
	Deadline    *time.Time     `db:"deadline"`    // The time after which the job should no longer be run
	RunAfter    time.Time      `db:"run_after"`   // The time after which the job is elligible to be picked up by a worker
	RanAt       null.Time      `db:"ran_at"`      // The last time the job ran
	Error       null.String    `db:"error"`       // The last error the job elicited
	Retries     int            `db:"retries"`     // The number of times the job has retried
	MaxRetries  *int           `db:"max_retries"` // The maximum number of times the job can retry
	CreatedAt   time.Time      `db:"created_at"`  // The time the job was created
}

Job contains all the data pertaining to jobs

Jobs are what are placed on queues for processing.

The Fingerprint field can be supplied by the user to impact job deduplication. TODO Factor out usage of the null package: github.com/guregu/null

func FromContext added in v0.5.0

func FromContext(ctx context.Context) (j *Job, err error)

FromContext fetches the job from a context if the job context variable is set

Jump to

Keyboard shortcuts

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