workman

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2017 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package workman is a Worker Manager Code based on http://marcio.io/2015/07/handling-1-million-requests-per-minute-with-golang/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(c *Flags) func(wm *WorkMan) error

Config sets store config from flag var

func Logger

func Logger(l *logger.Log) func(wm *WorkMan) error

Logger sets logger

Types

type Flags

type Flags struct {
	MaxWorkers int `long:"max_worker" default:"2" description:"Number of workers"`
	MaxQueue   int `long:"max_queue"  default:"100" description:"Max queue len"`
}

Flags is a package flags sample in form ready for use with github.com/jessevdk/go-flags

type Job

type Job struct {
	Payload string
	Result  chan Result
}

Job represents the job to be run

type Result

type Result struct {
	Success bool             `json:"success"`
	Error   interface{}      `json:"error,omitempty"`
	Result  *json.RawMessage `json:"result,omitempty"`
}

Result stores RPC result

type WorkMan

type WorkMan struct {
	JobQueue   chan Job       // A buffered channel that we can send work requests on.
	WorkerPool chan chan Job  // A pool of workers channels that are registered with the WorkMan
	QuitPool   chan chan bool // A pool of channels listens for quit
	QuitMain   chan bool
	WorkerFunc WorkerFunc
	Config     *Flags
	WG         *sync.WaitGroup
	Log        *logger.Log
}

WorkMan struct holds worker manager attributes

func New

func New(workerFunc WorkerFunc, options ...func(*WorkMan) error) (*WorkMan, error)

New - constructor

func (*WorkMan) Dump

func (wm *WorkMan) Dump() error

Dump object fields

func (*WorkMan) Run

func (wm *WorkMan) Run()

Run starts a set of workers

func (*WorkMan) Stop

func (wm *WorkMan) Stop()

Stop stops all started workers

type Worker

type Worker struct {
	WorkerPool  chan chan Job
	WorkerFunc  WorkerFunc
	JobChannel  chan Job
	QuitChannel chan bool
	Log         *logger.Log
	// contains filtered or unexported fields
}

Worker represents the worker that executes the job

func NewWorker

func NewWorker(wf WorkerFunc, workerPool chan chan Job, log *logger.Log, wg *sync.WaitGroup) Worker

NewWorker creates a worker instance

func (Worker) Start

func (w Worker) Start(id int)

Start method starts the run loop for the worker, listening for a quit channel in case we need to stop it

type WorkerFunc

type WorkerFunc func(payload string) Result

WorkerFunc is a function to be run by workers

Jump to

Keyboard shortcuts

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