workq

package
v0.0.0-...-af321b4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPopInterval     = time.Minute
	DefaultConcurrency     = 5
	DefaultCleanupInterval = time.Hour
	MaximumAttempts        = 100
)

Variables

View Source
var GlobalRegistry = &Registry{}

A default registry that other packages can easily register their types against.

View Source
var MaxCoolOffDuration = 240 * time.Second

Functions

func RegisterHandler

func RegisterHandler(jobType string, h interface{})

Register a job and handler with the default registry.

func RegisterPeriodicJob

func RegisterPeriodicJob(name, queue, jobType string, v interface{}, period time.Duration)

Types

type Handler

type Handler interface {
	PerformJob(jobType string, data []byte) error
}

type Injector

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

func (*Injector) AddPeriodicJob

func (i *Injector) AddPeriodicJob(name, queue, jt string, v interface{}, period time.Duration) error

func (*Injector) AddPeriodicJobRaw

func (i *Injector) AddPeriodicJobRaw(name, queue, jt string, payload []byte, period time.Duration) error

func (*Injector) Inject

func (i *Injector) Inject(job *Job) error

type Job

type Job struct {
	Id      []byte `gorm:"primary_key"`
	Queue   string
	Status  string
	JobType string
	Payload []byte

	CoolOffUntil *time.Time
	Attempts     int

	CreatedAt time.Time
}

func NewJob

func NewJob() *Job

func (*Job) Set

func (j *Job) Set(jt string, v interface{}) error

type PeriodicJob

type PeriodicJob struct {
	Id      int `gorm:"primary_key"`
	Name    string
	Queue   string
	JobType string
	Payload []byte
	Period  string
	NextRun time.Time

	CreatedAt time.Time
}

type Registry

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

func (*Registry) Handle

func (r *Registry) Handle(ctx context.Context, job *Job) error

func (*Registry) PrintHandlers

func (r *Registry) PrintHandlers(L hclog.Logger)

func (*Registry) Register

func (r *Registry) Register(jobType string, h interface{})

func (*Registry) Size

func (r *Registry) Size() int

type RunConfig

type RunConfig struct {
	ConnInfo     string
	PopInterval  time.Duration
	Concurrency  int
	CleanupCheck time.Duration
	Handler      func(ctx context.Context, j *Job) error
}

type RunningJob

type RunningJob struct {
	Job
	L hclog.Logger
	// contains filtered or unexported fields
}

func (*RunningJob) Abort

func (r *RunningJob) Abort() error

func (*RunningJob) AbortAndRequeue

func (r *RunningJob) AbortAndRequeue() error

func (*RunningJob) Close

func (r *RunningJob) Close() error

type Worker

type Worker struct {
	L hclog.Logger

	Validate func(job *Job) (bool, error)

	Stats struct {
		ListenWakeups int64
	}
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(L hclog.Logger, db *gorm.DB, queues []string) *Worker

func (*Worker) CheckPeriodic

func (w *Worker) CheckPeriodic() error

func (*Worker) CleanupFinished

func (w *Worker) CleanupFinished(lag bool) error

Cleanup all the finished jobs

func (*Worker) Pop

func (w *Worker) Pop() (*RunningJob, error)

func (*Worker) Run

func (w *Worker) Run(ctx context.Context, cfg RunConfig) error

Setup a pq listener and watch for events (and still pop every once in a while)"

Jump to

Keyboard shortcuts

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