Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(context.Context, ...interface{}) error

Handler function which will be called by the go routine

type Logger

type Logger interface {
	Print(*Pool, []interface{}, error)
}

Logger will be called if error occurred. @params: pool, job value, error

type Pool

type Pool struct {
	Tag string //tag used to identify a pool
	// contains filtered or unexported fields
}

Pool contains the jobs

func NewPool

func NewPool(size int, tag string, logger Logger) *Pool

NewPool will create new pool

Example
pool := NewPool(1, "Tag", myLogger{})
pool.AddWorker(2, egPrint, true)
pool.AddJob(1)
pool.Close()
fmt.Println(pool.GetStats())
Output:

Tag: Woker 2 Jobs: Total 1 Success 1 Error 0 Retry 0

func NewSimplePool

func NewSimplePool(size int) *Pool

NewSimplePool will create new pool without any logger and tag

Example
pool := NewSimplePool(1)
pool.AddWorker(2, egPrint, true)
pool.AddJob(1)
pool.Close()
fmt.Println(pool.GetStats())
Output:

Pool: Woker 2 Jobs: Total 1 Success 1 Error 0 Retry 0

func (*Pool) AddJob

func (p *Pool) AddJob(value ...interface{})

AddJob will enqueue job in the pool

func (*Pool) AddWorker

func (p *Pool) AddWorker(n int, handler Handler, start ...bool)

AddWorker will add worker in the pool. If start value is true then it will immediately start the worker as well

func (*Pool) Close

func (p *Pool) Close()

Close will close the pool

func (*Pool) CloseGracefully

func (p *Pool) CloseGracefully()

CloseGracefully will terminate all worker gracefully

func (*Pool) ErrorCount

func (p *Pool) ErrorCount() int

ErrorCount will return error count

func (*Pool) GetErrorPool

func (p *Pool) GetErrorPool() <-chan *WorkerJob

GetErrorPool will return error pool if any error occurred then worker will push that error on error pool

func (*Pool) GetStats

func (p *Pool) GetStats() string

GetStats will return pool stats

func (*Pool) PoolCap

func (p *Pool) PoolCap() int

PoolCap will return pool capacity

func (*Pool) PoolLen

func (p *Pool) PoolLen() int

PoolLen will return pool length

func (*Pool) RetryCount

func (p *Pool) RetryCount() int

RetryCount will return retry count

func (*Pool) SetBatchProfiler

func (p *Pool) SetBatchProfiler(batchSize int)

SetBatchProfiler will set profiler by job processed batch will fill print/log the job done in given batch size

func (*Pool) SetConsoleLog

func (p *Pool) SetConsoleLog(enable bool)

SetConsoleLog will enable/disable console logging

func (*Pool) SetLogger

func (p *Pool) SetLogger(logger Logger)

SetLogger will set logger

func (*Pool) SetMaxRetry

func (p *Pool) SetMaxRetry(n int)

SetMaxRetry will set max retries for jobs. Default value is 0

func (*Pool) SetRetryExponent

func (p *Pool) SetRetryExponent(n float64)

SetRetryExponent will set retry exponential base value

func (*Pool) SetTag

func (p *Pool) SetTag(tag string)

SetTag will set tag in the pool to identify the pool

func (*Pool) SetTimeProfiler

func (p *Pool) SetTimeProfiler(dur time.Duration)

SetTimeProfiler will set profiler by time

func (*Pool) Start

func (p *Pool) Start()

Start will start all the workers added in the pool

func (*Pool) Stats

func (p *Pool) Stats()

Stats will print pool stats

func (*Pool) SuccessCount

func (p *Pool) SuccessCount() int

SuccessCount will return success count

func (*Pool) TotalCount

func (p *Pool) TotalCount() int

TotalCount will return total count

func (*Pool) WorkerCount

func (p *Pool) WorkerCount() int

WorkerCount will return worker count

type Worker

type Worker struct {
	ID int //worker ID
	// contains filtered or unexported fields
}

Worker will perform the job

type WorkerJob

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

WorkerJob : job assigned to a worker

func (*WorkerJob) GetError

func (wj *WorkerJob) GetError() []error

GetError will return errors

func (*WorkerJob) GetValue

func (wj *WorkerJob) GetValue() []interface{}

GetValue will return job value

func (*WorkerJob) String

func (wj *WorkerJob) String() string