job

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CRC16("github.com/privatix/dappctrl/job") = 0x765D
	ErrAlreadyProcessing errors.Error = 0x765D<<8 + iota
	ErrDuplicatedJob
	ErrHandlerNotFound
	ErrQueueClosed
	ErrSubscriptionExists
	ErrSubscriptionNotFound
	ErrInternal
)

Errors.

View Source
const (
	MockAdd = iota
	MockProcess
	MockClose
	MockSubscribe
	MockUnsubscribe
)

Mock methods.

Variables

This section is empty.

Functions

func AddSimple

func AddSimple(q Queue, tx *reform.TX,
	jobType, relatedType, relatedID, creator string) error

AddSimple is convenience method to add a job.

func AddWithData

func AddWithData(q Queue, tx *reform.TX,
	jobType, relatedType, relatedID, creator string,
	jobData interface{}) error

AddWithData is convenience method to add a job with given data.

func AddWithDataAndDelay

func AddWithDataAndDelay(q Queue, tx *reform.TX,
	jobType, relatedType, relatedID, creator string,
	jobData interface{}, delay time.Duration) error

AddWithDataAndDelay is convenience method to add a job with given data and delay.

func AddWithDelay

func AddWithDelay(q Queue, tx *reform.TX,
	jobType, relatedType, relatedID, creator string,
	delay time.Duration) error

AddWithDelay is convenience method to add a job with given data delay.

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 interface {
	Add(tx *reform.TX, j *data.Job) error
	Process() error
	Close()
	Subscribe(subKeys []string, subID string, subFunc SubFunc) error
	Unsubscribe(subKeys []string, subID string) error
}

Queue is a job processing queue.

func NewQueue

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

NewQueue creates a new job queue.

type QueueMock

type QueueMock func(method int, tx *reform.TX, job *data.Job,
	relatedIDs []string, subID string, subFunc SubFunc) error

QueueMock is a queue method handler.

func NewDummyQueueMock

func NewDummyQueueMock() QueueMock

NewDummyQueueMock returns a queue mock which does nothing.

func (QueueMock) Add

func (q QueueMock) Add(tx *reform.TX, j *data.Job) error

Add is a mock implementation for the Add queue method.

func (QueueMock) Close

func (q QueueMock) Close()

Close is a mock implementation for the Close queue method.

func (QueueMock) Process

func (q QueueMock) Process() error

Process is a mock implementation for the Process queue method.

func (QueueMock) Subscribe

func (q QueueMock) Subscribe(
	relatedIDs []string, subID string, subFunc SubFunc) error

Subscribe is a mock implementation for the Subscribe queue method.

func (QueueMock) Unsubscribe

func (q QueueMock) Unsubscribe(relatedIDs []string, subID string) error

Unsubscribe is a mock implementation for the Unsubscribe queue method.

type SubFunc

type SubFunc func(job *data.Job, result error)

SubFunc is a job result notification callback.

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.
	FirstStartDelay uint  // Default first run delay after job added, in milliseconds.
}

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