Documentation
¶
Index ¶
- Constants
- func DefaultJobNameGenerator(job worker.Job) string
- func NewBoltDB(bo *Options) *boltDB
- type BoltWorker
- func (bw *BoltWorker) LoadPendingJobs()
- func (bw *BoltWorker) Perform(job worker.Job) error
- func (bw *BoltWorker) PerformAt(job worker.Job, t time.Time) error
- func (bw *BoltWorker) PerformIn(job worker.Job, d time.Duration) error
- func (bw *BoltWorker) Register(name string, h worker.Handler) error
- func (bw *BoltWorker) SpawnWorkers()
- func (bw *BoltWorker) Start(ctx context.Context) error
- func (bw *BoltWorker) Stop() error
- func (bw *BoltWorker) SyncWithDB() error
- type JobNameGenerator
- type Logger
- type Options
- type RetryJobError
Constants ¶
const ( //JobPending denotes the job is pending JobPending jobStatusCode = 1 << iota //JobInProcess denotes the job is being worked by a worker JobInProcess //JobReAttempt denotes the job needs a retry JobReAttempt //JobFailed denotes the job has failed and no need to reattempt JobFailed //JobDone denotes the job completed successfully JobDone )
Variables ¶
This section is empty.
Functions ¶
func DefaultJobNameGenerator ¶
DefaultJobNameGenerator is the default job name generator which assigns a uuid version 4 id to the job
Types ¶
type BoltWorker ¶
type BoltWorker struct { Logger Logger DB *boltDB DBSyncInterval time.Duration IdleSleepTime time.Duration BusyWorkerSleepTime time.Duration Concurrency int RetryAttempts int // contains filtered or unexported fields }
BoltWorker is a basic implementation of buffalo worker interface which persists job data in boltDB
func NewBoltWorker ¶
func NewBoltWorker(opts Options) *BoltWorker
NewBoltWorker creates a buffalo worker interface implementation which persists data in boltDB defined in the opts
func NewBoltWorkerWithContext ¶
func NewBoltWorkerWithContext(ctx context.Context, opts Options) *BoltWorker
NewBoltWorkerWithContext creates a buffalo worker interface implementation which persists data in boltDB defined in opts
func (*BoltWorker) LoadPendingJobs ¶
func (bw *BoltWorker) LoadPendingJobs()
LoadPendingJobs loads all the pending jobs from the boltDB to the Job Queue
func (*BoltWorker) Perform ¶
func (bw *BoltWorker) Perform(job worker.Job) error
Perform a job, the job is first saved to boltDB and then performed
func (*BoltWorker) PerformAt ¶
PerformAt perfirms a job at a particular time, the job is first saved to boltDB
func (*BoltWorker) PerformIn ¶
PerformIn performs a job after waiting for a specified time, the job is first saved to boltDB
func (*BoltWorker) Register ¶
func (bw *BoltWorker) Register(name string, h worker.Handler) error
Register a work handler with the name of the work
func (*BoltWorker) SpawnWorkers ¶
func (bw *BoltWorker) SpawnWorkers()
SpawnWorkers creates concurrent worker goroutines based on the MaxConcurrency option provided
func (*BoltWorker) SyncWithDB ¶
func (bw *BoltWorker) SyncWithDB() error
SyncWithDB syncs the jobQueue with DB, not threadsafe and needs to be called within a mutex Lock No other concurrent operations with the jobQueue should take place.
type JobNameGenerator ¶
JobNameGenerator function that will be run to determine the key for the job which will be saved in boltDB
type Logger ¶
type Logger interface { Debugf(string, ...interface{}) Infof(string, ...interface{}) Errorf(string, ...interface{}) Debug(...interface{}) Info(...interface{}) Error(...interface{}) }
Logger is used by the worker to write logs
type Options ¶
type Options struct { BoltOptions bolt.Options Logger Logger Name string MaxConcurrency int FilePath string CompletedBucket string PendingBucket string FailedBucket string DBSyncInterval string MaxRetryAttempts int IdleSleepTime string JobNameHandler JobNameGenerator }
Options are used to configure boltWorker
type RetryJobError ¶
RetryJobError denotes jobs which temporarily failed and should be retried
func NewRetryJobError ¶
func NewRetryJobError(msg string) RetryJobError
NewRetryJobError returns an instance of RetryJobError, this denotes a temporary failure and the job will be retried
func (RetryJobError) Error ¶
func (e RetryJobError) Error() string
Error returns the error as a string
func (*RetryJobError) SetRetryTime ¶
func (e *RetryJobError) SetRetryTime(t time.Duration)
SetRetryTime sets the retry time in time.Duration