Documentation
¶
Index ¶
- Variables
- type Boss
- func (b *Boss) AddJob(workerName string, j Job) error
- func (b *Boss) AddJobCtx(ctx context.Context, workerName string, j Job) error
- func (b *Boss) HasWorker(name string) bool
- func (b *Boss) HireWorker(name string, queueLength int) error
- func (b *Boss) PlaceWorker(worker Worker) error
- func (b *Boss) RemoveStaleWorkers(deadline time.Time) int
- func (b *Boss) RemoveWorker(worker Worker)
- func (b *Boss) ScaleDownAll()
- func (b *Boss) ScaleDownWorker(workerName string) error
- func (b *Boss) TerminateAll()
- func (b *Boss) TerminateWorker(workerName string) (err error)
- func (b *Boss) Worker(name string) (worker Worker)
- type BossConf
- type HR
- type HiringAgencyFunc
- type Job
- type JobResponse
- type LoggingWorker
- type ManagedWorker
- type PitDroid
- type StatWorker
- type Worker
- type WorkerStatistics
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Boss ¶
type Boss struct {
// contains filtered or unexported fields
}
Boss controls the life of the workers
func (*Boss) HireWorker ¶
HireWorker will attempt to hire a new worker using the specified HiringAgency and add them to the job pool.
func (*Boss) PlaceWorker ¶
PlaceWorker will attempt to add a hired worker to the job pool, if one doesn't already exist with that name
func (*Boss) RemoveStaleWorkers ¶
RemoveStaleWorkers terminate workers that have not processed a job after the provided deadline. Note: this requires that workers implement the StatWorker interface. Otherwise, this func does nothing but block for a short while.
func (*Boss) RemoveWorker ¶
func (*Boss) ScaleDownAll ¶
func (b *Boss) ScaleDownAll()
ShutdownAll will attempt to gracefully shutdown, completing all currently queued jobs but no longer accepting new ones
func (*Boss) ScaleDownWorker ¶
ScaleDownWorker will tell a worker to finish up their queue then remove them
func (*Boss) TerminateAll ¶
func (b *Boss) TerminateAll()
TerminateAll will immediately fire all current workers, dropping all currently queued jobs.
func (*Boss) TerminateWorker ¶
TerminateWorker will remove the worker immediately, effectively cancelling all queued work.
type BossConf ¶
func DefaultConfig ¶
func DefaultConfig() *BossConf
type HR ¶
type HR func(Worker)
HR is where workers are sent when they are done and should be removed from the Boss
type HiringAgencyFunc ¶
var HiringAgency HiringAgencyFunc = NewPitDroid
HiringAgency allows you to create your own worker hiring function in case you don't like PitDroids.
type Job ¶
type Job interface { // Process must contain whatever logic is needed to perform the job, returning whatever error is generated while // processing (if any) Process() error // RespondTo must be passed whatever output came from Process() RespondTo() chan<- *JobResponse }
Job represents any unit of work that you'd like to task a Worker with. Any context handling should be done in your Process() implementation.
type JobResponse ¶
type JobResponse struct { JobType string Placed time.Time Start time.Time End time.Time Worker string Err error // contains filtered or unexported fields }
JobResponse wraps the output of a job upon completion, whether it is successful or not.
type LoggingWorker ¶
type ManagedWorker ¶
type PitDroid ¶
type PitDroid struct {
// contains filtered or unexported fields
}
PitDroids are simple workers that will do as instructed.
func (*PitDroid) AddJob ¶
AddJob will append a job to this worker's queue. The context is used to limit how long a worker can try to push a job onto its queue before failing. It does not limit the job's execution time.
func (*PitDroid) ScaleDown ¶
func (pd *PitDroid) ScaleDown()
ScaleDown will tell this worker to stop accepting new jobs, complete all jobs left in its queue, then send itself to HR
func (*PitDroid) Statistics ¶
func (pd *PitDroid) Statistics() WorkerStatistics
type StatWorker ¶
type StatWorker interface { Worker Statistics() WorkerStatistics }
type Worker ¶
type Worker interface { // Name must return the name of worker. This must be unique across all workers managed by the boss Name() string // Length must return the size of the current queue of work for this worker. Length() int // AddJob must attempt to add a new job to the worker's queue, failing if the worker has been told to stop AddJob(context.Context, Job) error // ScaleDown must mark the worker as stopped, process any and all jobs remaining in it's queue ScaleDown() // Terminate must send an error message to all remaining jobs in this worker's queue Terminate() }
func NewPitDroid ¶
NewPitDroid will return to you a new PitDroid, the default worker prototype for jobber