workerpool

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Worker

type Worker interface {
	// Name should return a unique identifier for a particular worker
	Name() string
	// DoWork should receive a message, and perform the actual work, only an error should be returned
	DoWork(message interface{}) error
	// OnError will be called if DoWork returns an error != nil
	OnError(e error)
	// Cleanup will be called when the worker is shutting down
	Cleanup() error
	// FailureTime should return the amount of time the worker should wait after resuming work if an error occurs
	FailureTime() int64
}

Worker interface should be implemented by concrete workers that will perform the actual job

type WorkerAdmin

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

WorkerAdmin struct handles multiple worker execution, popping jobs from a single queue

func NewWorkerAdmin

func NewWorkerAdmin(queueSize int, logger logging.LoggerInterface) *WorkerAdmin

NewWorkerAdmin instantiates a new WorkerAdmin and returns a pointer to it.

func (*WorkerAdmin) AddWorker

func (a *WorkerAdmin) AddWorker(w Worker)

AddWorker registers a new worker in the admin

func (*WorkerAdmin) IsWorkerRunning

func (a *WorkerAdmin) IsWorkerRunning(name string) bool

IsWorkerRunning returns true if the worker exists and is currently running

func (*WorkerAdmin) QueueMessage

func (a *WorkerAdmin) QueueMessage(m interface{}) bool

QueueMessage adds a new message that will be popped by a worker and processed

func (*WorkerAdmin) QueueSize

func (a *WorkerAdmin) QueueSize() int

QueueSize returns the current queue size

func (*WorkerAdmin) StopAll

func (a *WorkerAdmin) StopAll(blocking bool) error

StopAll ends all worker's event loops

func (*WorkerAdmin) StopWorker

func (a *WorkerAdmin) StopWorker(name string, blocking bool) error

StopWorker ends the worker's event loop, preventing it from picking further jobs

Jump to

Keyboard shortcuts

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