worker

package
v0.0.0-...-beb54cf Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package workers provides primitives for configuration and starting worker queues

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	//Number of pre-initialized task thread
	Concurrency int

	//Waiting time for worker to wait task threads closing
	WaitTaskThreadsToClose time.Duration

	//Waiting time to issue heartbeat
	Heartbeat time.Duration
}

Configuration stores initialization data for worker server

func NewConfiguration

func NewConfiguration() *Configuration

type EventHandler

type EventHandler interface {
	//TODO: Remove Start and End handlers. It can be solved with decorator
	OnStartWorker()
	OnEndWorker()

	//TODO: Remove Pre and Post handlers. It can be solved with decorator
	OnPreTask(task *common.Task)
	OnPostTask(task *common.Task)
	OnThreadHeartbeat(threadId int)
}

type Handler

type Handler interface {
	Init() error
	Close() error

	Config() *Configuration

	TaskQueue() chan<- *common.Task
	SetEventHandler(eventHandler EventHandler)
	SetTaskEventHandler(eventHandler common.TaskProcessEventHandler)
	StartWorker()
	StopWorker()
}

type Worker

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

TODO: Benchmark tests Worker stores configuration for server activation

func NewWorker

func NewWorker(config *Configuration, connectorHandler connector.Handler) *Worker

NewWorker creates and configures Worker instance

func (*Worker) Close

func (w *Worker) Close() error

func (*Worker) Config

func (w *Worker) Config() *Configuration

func (*Worker) Init

func (w *Worker) Init() error

func (*Worker) OnEndWorker

func (w *Worker) OnEndWorker()

func (*Worker) OnPostTask

func (w *Worker) OnPostTask(task *common.Task, threadId int)

func (*Worker) OnPreTask

func (w *Worker) OnPreTask(task *common.Task, threadId int)

func (*Worker) OnStartWorker

func (w *Worker) OnStartWorker()

func (*Worker) OnTaskError

func (w *Worker) OnTaskError(task *common.Task, err error)

func (*Worker) OnTaskHeartbeat

func (w *Worker) OnTaskHeartbeat(task *common.Task)

func (*Worker) OnTaskResult

func (w *Worker) OnTaskResult(task *common.Task, a ...interface{})

func (*Worker) OnTaskSuccess

func (w *Worker) OnTaskSuccess(task *common.Task)

func (*Worker) OnThreadHeartbeat

func (w *Worker) OnThreadHeartbeat(threadId int)

func (*Worker) SetEventHandler

func (w *Worker) SetEventHandler(eventHandler EventHandler)

SetEventHandler

func (*Worker) SetTaskEventHandler

func (w *Worker) SetTaskEventHandler(eventHandler common.TaskProcessEventHandler)

SetTaskEventHandler

func (*Worker) StartWorker

func (w *Worker) StartWorker()

StartWorker starts workers server

func (*Worker) StopWorker

func (w *Worker) StopWorker()

StopWorker stops workers server

func (*Worker) TaskQueue

func (w *Worker) TaskQueue() chan<- *common.Task

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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