Documentation ¶
Overview ¶
Package jobmgr Created by RTT. Author: teocci@yandex.com on 2021-Aug-18
Package jobmgr Created by RTT. Author: teocci@yandex.com on 2021-Aug-18
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct { Workers []*Worker // this is the list of workers that dispatcher tracks JobChan JobChannel // client submits job to this channel Queue JobQueue // this is the shared JobPool between the workers }
Dispatcher is the link between the client and the workers
func NewDispatcher ¶
func NewDispatcher(num int) *Dispatcher
NewDispatcher returns a new dispatcher. A Dispatcher communicates between the client and the worker. Its main job is to receive a job and share it on the WorkPool. A WorkPool is the link between the dispatcher and all the workers as the WorkPool of the dispatcher is common JobPool for all the workers
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start(fn TaskFunc) *Dispatcher
Start creates pool of num count of workers.
func (*Dispatcher) Submit ¶
func (d *Dispatcher) Submit(job Job)
type Job ¶
Job represents a single entity that should be processed. For example a struct that should be saved to database
type JobChannel ¶
type JobChannel chan Job
type Worker ¶
type Worker struct { ID int // id of the worker JobChan JobChannel // a channel to receive single unit of work Queue JobQueue // shared between all workers. Quit chan struct{} // a channel to quit working }
Worker is a single processor. Typically, it is possible to start multiple workers for better throughput