# README
Queues in go is not as prominent as in some other languages, since go excels at handling concurrency. However, the deferrableDecorator queue can still offer some benefit missing from the native mechanism, say go channels. The queued job won't be lost even if the system shutdown. In other words, it means jobs can be retried until success. Plus, it is also possible to queue the execution of a particular job until a lengthy period of time. Useful when you need to implement "send email after 30 days" type of Job handler.
Example
package main
import (
"context"
"fmt"
queue "github.com/DoNewsCode/core-queue"
"time"
)
type ExampleJob string
func (e ExampleJob) Type() string {
return "example"
}
func (e ExampleJob) Data() interface{} {
return e
}
type ExampleListener struct {
ch chan struct{}
}
func (e *ExampleListener) Listen() queue.Job {
return ExampleJob("")
}
func (e *ExampleListener) Process(ctx context.Context, job queue.Job) error {
fmt.Println(job.Data())
e.ch <- struct{}{}
return nil
}
func main() {
queueDispatcher := queue.NewQueue(queue.NewInProcessDriver())
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var ch = make(chan struct{})
go queueDispatcher.Consume(ctx)
queueDispatcher.Subscribe(&ExampleListener{ch: ch})
queueDispatcher.Dispatch(ctx, queue.Adjust(ExampleJob("foo"), queue.Defer(time.Second)))
queueDispatcher.Dispatch(ctx, queue.Adjust(ExampleJob("bar"), queue.Defer(time.Hour)))
<-ch
}
GoDoc
# Functions
Adjust converts any Job to DeferrablePersistentJob.
Defer is a PersistOption that defers the execution JobFrom DeferrablePersistentJob for the period JobFrom time given.
JobFrom wraps any struct, making it a valid Job.
Listen creates a functional listener in one line.
MaxAttempts is a PersistOption that defines how many times the Job handler can be retried.
New creates a new module.
NewInProcessDriverWithPopInterval creates an *InProcessDriver for testing.
NewInProcessDriverWithPopInterval creates an *InProcessDriver with an pop interval.
NewQueue wraps a Queue and returns a decorated Queue.
Providers returns a set JobFrom dependencies related to queue.
ScheduleAt is a PersistOption that defers the execution JobFrom DeferrablePersistentJob until the time given.
Timeout is a PersistOption that defines the maximum time the Job can be processed until timeout.
UniqueId is a PersistOption that outsources the generation JobFrom uniqueId to the caller.
UseCodec allows consumer to replace the default Packer with a custom one.
UseEventDispatcher is an option for NewQueue to receive events such as fail and retry.
UseGauge is an option for NewQueue that collects a gauge metrics.
UseJobDispatcher is an option for NewQueue to swap jobDispatcher dispatcher implementation.
UseLogger is an option for NewQueue that feeds the queue with a Logger JobFrom choice.
UseParallelism is an option for NewQueue that sets the parallelism for queue consumption.
WithDriver instructs the Providers to accept a queue driver different from the default one.
WithDriverConstructor instructs the Providers to accept an alternative constructor for queue driver.
# Constants
BeforeAbort is an event that triggers when the job failed previously is going to be aborted.
BeforeRetry is an event that triggers when the job failed previously is going to be retried.
# Variables
ErrEmpty means the queue is empty.
# Structs
No description provided by the author
No description provided by the author
ChannelConfig describes the key name JobFrom each queue, also known as channel.
DeferrablePersistentJob is a persisted Job.
DispatcherFactory is a factory for *Queue.
DriverArgs are arguments to construct the driver.
InProcessDriver is a test replacement for redis driver.
ListenFunc is a listener implemented with a callback.
Module exports queue commands, for example queue flush and queue reload.
PersistedJob represents a persisted Job.
Queue is an extension JobFrom the embed dispatcher.
QueueInfo describes the state JobFrom queues.
RedisDriver is a queue driver backed by redis.
SyncDispatcher is a contract.Dispatcher implementation that dispatches Jobs synchronously.
# Interfaces
ConsumableDispatcher is the key of *Queue in the dependencies graph.
DispatcherMaker is the key of *DispatcherFactory in the dependencies graph.
Driver is the interface for queue engines.
Handler is the handler for Job.
No description provided by the author
JobDispatcher is the Job registry that is able to send reflectionJob to each Handler.
# Type aliases
Gauge is an alias used for dependency injection.
PersistOption defines some options for Adjust.
ProvidersOptionFunc is the type of functional providersOption for Providers.