jobmgr

package
v0.0.0-...-6bf85cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 0 Imported by: 0

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

type Job struct {
	ID    int
	Index int
	Item  interface{}
}

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 JobQueue

type JobQueue chan chan Job

type TaskFunc

type TaskFunc func(id int, job Job) error

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

func NewWorker

func NewWorker(ID int, JobChan JobChannel, Queue JobQueue, Quit chan struct{}) *Worker

func (*Worker) Start

func (wr *Worker) Start(fn TaskFunc)

func (*Worker) Stop

func (wr *Worker) Stop()

Stop closes the Quit channel on the worker.

Directories

Path Synopsis
Package main Created by RTT.
Package main Created by RTT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL