Documentation ¶
Overview ¶
Package worker accepts Jobs and places them in a queue to be executed N at a time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MaxJobs = 4
MaxJobs is the default amount of jobs to run at a time. This can be changed per Worker object as well.
Functions ¶
This section is empty.
Types ¶
type ExitCode ¶
type ExitCode int
ExitCode is a code for how the Worker should exit.
const ( // ExitNormally indicates that the Worker is exiting without error. ExitNormally ExitCode = 0 // ExitWhenDone indicates that the Worker should finish all of its Jobs first, then exit. ExitWhenDone = 4 )
type Job ¶
type Job interface {
Run()
}
A Job is an object with a Run() method, which is expected to complete a given task. Jobs can be run in parallel, so any resources shared between Jobs should be thread-safe.
type JobStatus ¶
type JobStatus int
JobStatus indicates where in the execution process a Job (Package) is.
const ( // Queued means the Job is added to the Worker but hasn't started yet. Queued JobStatus = 1 << iota // Running means the Job has started executing its Run() method. Running // Finished means the Job has finished executing its Run() method and presumably has no errors. Finished // Errored means the Job errored at some point during the Run() method and has stopped executing. Errored )
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map holds a lookup table for Job Packages by ID.
type Package ¶
type Package struct { ID int64 // contains filtered or unexported fields }
Package is a type that wraps a more generic Job object and contains some meta information about the Job used by the Worker.
func NewPackage ¶
NewPackage wraps the given Job and assigned ID in a *Package and returns it.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
A Queue is an ordered list of Jobs.
type Stats ¶
Stats contains some information about the Packages that are Queued, Running, Finished, etc.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
A Worker holds and executes a bunch of jobs N at a time.
func NewWorker ¶
func NewWorker() *Worker
NewWorker returns a new Worker object with the maximum jobs at a time set to the default.
func (*Worker) RunUntilDone ¶
func (w *Worker) RunUntilDone()
RunUntilDone tells the Worker to run until all of its jobs are completed and then shut down and stop accepting Jobs.
func (*Worker) RunUntilStopped ¶
RunUntilStopped tells the Worker to run until it's explicitly told to stop via an ExitCode. It'll accept new Jobs until this happens.