Documentation ¶
Index ¶
- func SetLogger(l Logger)
- type Boss
- func (b *Boss) AddJob(workerName string, j Job) (err error)
- func (b *Boss) HasWorker(name string) bool
- func (b *Boss) HireWorker(name string, queueLength int) error
- func (b *Boss) PlaceWorker(worker Worker) (err error)
- func (b *Boss) ScaleDownWorker(workerName string) (err error)
- func (b *Boss) Shutdown()
- func (b *Boss) Shutdowned() bool
- func (b *Boss) Terminate()
- func (b *Boss) TerminateWorker(workerName string) (err error)
- func (b *Boss) Worker(name string) (worker Worker)
- type HR
- type HiringAgencyFunc
- type Job
- type Logger
- type PitDroid
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Boss ¶
type Boss struct {
// contains filtered or unexported fields
}
Boss controls the life of the workers
func NewBossWithContext ¶
NewBossWithContext will create a new Boss with a context of your creation
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) ScaleDownWorker ¶
ScaleDownWorker will tell a worker to finish up their queue then remove them
func (*Boss) Shutdown ¶
func (b *Boss) Shutdown()
Shutdown will attempt to gracefully shutdown, completing all currently queued jobs but no longer accepting new ones
func (*Boss) Shutdowned ¶
Shutdowned will return true if the boss has been told to shut down or terminate
func (*Boss) Terminate ¶
func (b *Boss) Terminate()
Terminate will immediately fire all workers and shut down the boss
func (*Boss) TerminateWorker ¶
TerminateWorker will remove the worker immediately, effectively cancelling all queued work.
type HR ¶
type HR chan<- 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<- error }
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 PitDroid ¶
type PitDroid struct {
// contains filtered or unexported fields
}
PitDroids are simple workers that will do as instructed.
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(Job) error // ScaleDown must mark the worker as stopped, process any and all jobs remaining in it's queue, and then finally // send itself to HR ScaleDown(HR) // Terminate must send an error message to all remaining jobs in this worker's queue, then send itself to HR. Terminate(HR) }
func NewPitDroid ¶
NewPitDroid will return to you a new PitDroid, the default worker prototype for jobber