worker

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: BSD-3-Clause Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(worker Worker)

Register registers specific type with its full package path as key

func RegisterFunc

func RegisterFunc(name string, fn FuncInterface)

RegisterFunc registers func worker into registry which could be fetch through GetFunc(name string)

func RegisterInst

func RegisterInst(worker Worker)

RegisterInst registers an instance provided instead of its type

func RegisterInstName

func RegisterInstName(name string, worker Worker)

RegisterInstName registers an instance with given name

func RegisterName

func RegisterName(name string, worker Worker)

RegisterName registers specific type with specific name as key

Types

type FuncInterface

type FuncInterface func(strategyId, parameter string)

FuncInterface defines the func used in scheduling.

Generally it's better keeping invocation fast but if it costs much more time
maybe you should carefully set a suitable timeout during shutdown.

func GetFunc

func GetFunc(name string) FuncInterface

type FuncWorker

type FuncWorker struct {
	sync.Mutex

	// TimeoutShutdown is the timeout when waiting to close the worker
	TimeoutShutdown time.Duration
	// contains filtered or unexported fields
}

FuncWorker uses a func to implement a task loop. A channel is used to do nififications(ping-pong).

func (*FuncWorker) FuncExecutor

func (w *FuncWorker) FuncExecutor()

func (*FuncWorker) NeedStop

func (w *FuncWorker) NeedStop() bool

func (*FuncWorker) Start

func (w *FuncWorker) Start(strategyId, parameter string)

func (*FuncWorker) Stop

func (w *FuncWorker) Stop(strategyId, parameter string)

type Worker

type Worker interface {
	Start(strategyId, parameter string)
	Stop(strategyId, parameter string)
}

Worker manages data of scheduling for binded strategy

func GetWorker

func GetWorker(name string) Worker

func NewFunc

func NewFunc(strategy definition.Strategy) (Worker, error)

func NewSimple

func NewSimple(strategy definition.Strategy) (Worker, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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