job

package
v0.0.0-...-cb3ca1d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyProcessing = errors.New("already processing")
	ErrDuplicatedJob     = errors.New("duplicated job")
	ErrHandlerNotFound   = errors.New("job handler not found")
	ErrQueueClosed       = errors.New("queue closed")
)

Errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	CollectJobs   uint // Number of jobs to process for collect-iteration.
	CollectPeriod uint // Collect-iteration period, in milliseconds.
	WorkerBufLen  uint // Worker buffer length.
	Workers       uint // Number of workers, 0 means number of CPUs.

	TypeConfig                       // Default type configuration.
	Types      map[string]TypeConfig // Type-specific overrides.
}

Config is a job queue configuration.

func NewConfig

func NewConfig() *Config

NewConfig creates a default job queue configuration.

type Handler

type Handler func(j *data.Job) error

Handler is a job handler function.

type HandlerMap

type HandlerMap map[string]Handler

HandlerMap is a map of job handlers.

type Queue

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

Queue is a job processing queue.

func NewQueue

func NewQueue(conf *Config, logger *util.Logger, db *reform.DB,
	handlers HandlerMap) *Queue

NewQueue creates a new job queue.

func (*Queue) Add

func (q *Queue) Add(j *data.Job) error

Add adds a new job to the job queue.

func (*Queue) Close

func (q *Queue) Close()

Close causes currently running Process() function to exit.

func (*Queue) DB

func (q *Queue) DB() *reform.DB

DB is an associated reform.DB instance.

func (*Queue) Logger

func (q *Queue) Logger() *util.Logger

Logger is an associated util.Logger instance.

func (*Queue) Process

func (q *Queue) Process() error

Process fetches active jobs and processes them in parallel. This function does not return until an error occurs or Close() is called.

type TypeConfig

type TypeConfig struct {
	TryLimit   uint8 // Default number of tries to complete job.
	TryPeriod  uint  // Default retry period, in milliseconds.
	Duplicated bool  // Whether do or do not check for duplicates.
}

TypeConfig is a configuration for specific job type.

Jump to

Keyboard shortcuts

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