Documentation ¶
Index ¶
- Variables
- type Consumer
- type Job
- type Logger
- type Metric
- type Option
- type Options
- type Queue
- func (q *Queue) Capacity() int
- func (q *Queue) Queue(job QueuedMessage) error
- func (q *Queue) QueueTask(task TaskFunc) error
- func (q *Queue) QueueTaskWithTimeout(timeout time.Duration, task TaskFunc) error
- func (q *Queue) QueueWithTimeout(timeout time.Duration, job QueuedMessage) error
- func (q *Queue) Release()
- func (q *Queue) Shutdown()
- func (q *Queue) Start()
- func (q *Queue) Usage() int
- func (q *Queue) Wait()
- func (q *Queue) Workers() int
- type QueuedMessage
- type TaskFunc
- type Worker
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrMissingWorker = errors.New("missing worker module")
ErrMissingWorker missing define worker
View Source
var ErrQueueShutdown = errors.New("queue has been closed and released")
ErrQueueShutdown the queue is released and closed.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶ added in v0.0.7
type Consumer struct {
// contains filtered or unexported fields
}
Worker for simple queue using channel
func (*Consumer) BusyWorkers ¶ added in v0.0.8
func (*Consumer) Queue ¶ added in v0.0.7
func (s *Consumer) Queue(job QueuedMessage) error
Queue send notification to queue
type Job ¶
type Job struct { Task TaskFunc `json:"-"` Timeout time.Duration `json:"timeout"` Body []byte `json:"body"` }
Job with Timeout
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
func NewEmptyLogger ¶
func NewEmptyLogger() Logger
NewEmptyLogger for simple logger.
Example ¶
l := NewEmptyLogger() l.Info("test") l.Infof("test") l.Error("test") l.Errorf("test") l.Fatal("test") l.Fatalf("test")
Output:
type Metric ¶ added in v0.0.10
type Metric interface { IncBusyWorker() DecBusyWorker() BusyWorkers() uint64 }
Metric interface
type Option ¶
type Option func(*Options)
Option for queue system
func WithFn ¶ added in v0.0.7
func WithFn(fn func(context.Context, QueuedMessage) error) Option
WithFn set custom job function
func WithQueueSize ¶ added in v0.0.7
WithQueueSize set worker count
func WithTimeOut ¶ added in v0.0.9
WithTimeOut set custom timeout
type Options ¶ added in v0.0.7
type Options struct {
// contains filtered or unexported fields
}
func NewOptions ¶ added in v0.0.7
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
A Queue is a message queue.
func (*Queue) QueueTaskWithTimeout ¶
QueueTaskWithTimeout to queue job task with timeout
func (*Queue) QueueWithTimeout ¶
func (q *Queue) QueueWithTimeout(timeout time.Duration, job QueuedMessage) error
Queue to queue all job
type Worker ¶
type Worker interface { // BeforeRun is called before starting the worker BeforeRun() error // Run is called to start the worker Run() error // BeforeRun is called after starting the worker AfterRun() error // Shutdown is called if stop all worker Shutdown() error // Queue to send message in Queue (single channel, NSQ or AWS SQS) Queue(job QueuedMessage) error // Capacity queue capacity = cap(channel name) Capacity() int // Usage is how many message in queue Usage() int // BusyWorkers return count of busy worker currently BusyWorkers() uint64 }
Worker interface
Click to show internal directories.
Click to hide internal directories.