worker

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WorkQueue = make(chan WorkRequest, 100)
View Source
var WorkerQueue chan chan WorkRequest

Functions

func StartDispatcher

func StartDispatcher(nworkers int)

StartDispatcher is charged to start n workers.

Types

type ChanWriter

type ChanWriter struct {
	ByteChan chan []byte
}

ChanWriter is a simple writer to a channel of byte.

func (*ChanWriter) Write

func (c *ChanWriter) Write(p []byte) (int, error)

type WorkRequest

type WorkRequest struct {
	ID          uint64
	Name        string
	Script      string
	Payload     string
	Args        []string
	MessageChan chan []byte
	Timeout     int
	Terminated  bool
	// contains filtered or unexported fields
}

WorkRequest is a request of work for a worker

func NewWorkRequest added in v1.2.2

func NewWorkRequest(name, script, payload string, args []string, timeout int) *WorkRequest

NewWorkRequest creats new work request

func (*WorkRequest) IsTerminated added in v1.2.6

func (wr *WorkRequest) IsTerminated() bool

IsTerminated ask if the work request is terminated

func (*WorkRequest) Terminate added in v1.2.6

func (wr *WorkRequest) Terminate()

Terminate set work request as terminated

type Worker

type Worker struct {
	ID          int
	Work        chan WorkRequest
	WorkerQueue chan chan WorkRequest
	QuitChan    chan bool
}

Worker is a go routine in charge of executing a work.

func NewWorker

func NewWorker(id int, workerQueue chan chan WorkRequest) Worker

NewWorker creates, and returns a new Worker object. Its only argument is a channel that the worker can add itself to whenever it is done its work.

func (Worker) Start

func (w Worker) Start()

Start is the function to starts the worker by starting a goroutine. That is an infinite "for-select" loop.

func (Worker) Stop

func (w Worker) Stop()

Stop tells the worker to stop listening for work requests. Note that the worker will only stop *after* it has finished its work.

Jump to

Keyboard shortcuts

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