queue

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT Imports: 8 Imported by: 0

README

Queue

Run Tests

Queue is a Golang library for spawning and managing a Goroutine pool, Alloowing you to create multiple worker according to limit CPU number of machine.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingWorker = errors.New("missing worker module")

ErrMissingWorker missing define worker

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Info(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
}

Logger interface is used throughout gorush

type Option

type Option func(*Queue)

Option for queue system

func WithLogger

func WithLogger(l Logger) Option

WithLogger set custom logger

func WithWorker

func WithWorker(w Worker) Option

WithWorker set custom worker

func WithWorkerCount

func WithWorkerCount(num int) Option

WithWorkerCount set worker count

type Queue

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

A Queue is a message queue.

func NewQueue

func NewQueue(opts ...Option) (*Queue, error)

NewQueue returns a Queue.

func (*Queue) Capacity

func (q *Queue) Capacity() int

Capacity for queue max size

func (*Queue) Queue

func (q *Queue) Queue(job QueuedMessage) error

Queue to queue all job

func (*Queue) Shutdown

func (q *Queue) Shutdown()

Shutdown stops all queues.

func (*Queue) Start

func (q *Queue) Start()

Start to enable all worker

func (*Queue) Usage

func (q *Queue) Usage() int

Usage for count of queue usage

func (*Queue) Wait

func (q *Queue) Wait()

Wait all process

func (*Queue) Workers

func (q *Queue) Workers() int

Workers returns the numbers of workers has been created.

type QueuedMessage

type QueuedMessage interface {
	Bytes() []byte
}

QueuedMessage ...

type Worker

type Worker interface {
	BeforeRun() error
	Run(chan struct{}) error
	AfterRun() error

	Shutdown() error
	Queue(job QueuedMessage) error
	Capacity() int
	Usage() int
}

Worker interface

Jump to

Keyboard shortcuts

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