dispatcher

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorOfDispatcherHasStop = errors.New("dispatcher has stop")

ErrorOfDispatcherHasStop dispatcher is stop

Functions

This section is empty.

Types

type Config

type Config struct {
	Name         string
	MaxWorkerNum int
	MaxTaskNum   int
	IsTrance     bool
}

Config of dispatcher.

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher job to worker to do.

func GetDispatch

func GetDispatch(c Config, workDo workDoing, r Resource) *Dispatcher

GetDispatch Get a worker task queue model.

func (*Dispatcher) AddTask

func (d *Dispatcher) AddTask(t Task) error

AddTask add a job to do.

func (*Dispatcher) GetCurrentFreeWorkerNum

func (d *Dispatcher) GetCurrentFreeWorkerNum() int

GetCurrentFreeWorkerNum get current free worker number.

func (*Dispatcher) GetCurrentTaskTodoNum

func (d *Dispatcher) GetCurrentTaskTodoNum() int

GetCurrentTaskTodoNum get current job number wait to operate.

func (*Dispatcher) GetMaxTaskNum

func (d *Dispatcher) GetMaxTaskNum() int

GetMaxTaskNum get max number of job queue.

func (*Dispatcher) GetName

func (d *Dispatcher) GetName() string

GetName get dispatcher name.

func (*Dispatcher) GetState

func (d *Dispatcher) GetState() State

GetState get dispatcher state.

func (*Dispatcher) GetTotalDoneTask

func (d *Dispatcher) GetTotalDoneTask() uint64

GetTotalDoneTask get total number of job which all workers finish since dispatcher start.

func (*Dispatcher) GetTotalErrorTask

func (d *Dispatcher) GetTotalErrorTask() uint64

GetTotalErrorTask get total number of job which all workers operate error since dispatcher start.

func (*Dispatcher) GetTotalInTask

func (d *Dispatcher) GetTotalInTask() uint64

GetTotalInTask get total number of job which put in job queue since dispatcher start.

func (*Dispatcher) GetTotalRefusedTask

func (d *Dispatcher) GetTotalRefusedTask() uint64

GetTotalRefusedTask get total number of job which refuse because of job queue full since dispatcher start.

func (*Dispatcher) GetTotalWorkNum

func (d *Dispatcher) GetTotalWorkNum() int

GetTotalWorkNum get max number of worker.

func (*Dispatcher) IsStop

func (d *Dispatcher) IsStop() bool

IsStop is dispatcher has stop.

func (*Dispatcher) StartAgain

func (d *Dispatcher) StartAgain()

StartAgain dispatcher.

func (*Dispatcher) Status

func (d *Dispatcher) Status()

Status show the status of the current dispatcher.

func (*Dispatcher) StopForever

func (d *Dispatcher) StopForever(done chan struct{})

StopForever dispatcher, not accept task any more, but should finish all task that in queue, then every worker will quit, can't be start again.

func (*Dispatcher) StopTemporary

func (d *Dispatcher) StopTemporary()

StopTemporary dispatcher, not accept task any more, but should finish all task that in queue, can start again by call StartAgain().

type InData

type InData struct {
	TaskUID string
	Data    []byte
	If      interface{}
}

InData of Task.

type OutData

type OutData struct {
	Code int
	Err  error
	Data []byte
	If   interface{}
}

OutData of Task.

type Resource

type Resource interface {
	Check(ctx context.Context) (Resource, error)
	Release() error
}

Resource of worker own.

type State

type State int

State Dispatcher state

const (
	StateOfNormal State = iota
	StateOfHalf
	StateOfBusy
	StateOfDeny
)

state enum

type Task

type Task struct {
	OriginalCtx context.Context
	InData      InData
	OutCh       chan OutData
	TimeOut     time.Duration // per - Millisecond
	StartTime   int64
	EndTime     int64
}

Task that worker to operate.

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker is who operate job task.

Jump to

Keyboard shortcuts

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