Documentation
¶
Overview ¶
Package taskqueue provides a Redis-backed distributed task queue with at-least-once delivery semantics.
The queue maintains an in-flight processing set to track tasks currently being executed. A configurable recovery mechanism periodically moves stale tasks from the processing set back to the main queue, ensuring no task is lost if a worker crashes. The queue supports multiple concurrent workers.
Basic usage:
executor := &MyExecutor{}
queue, err := taskqueue.New(
redisClient,
"tasks:myapp",
executor,
taskqueue.WithWorkerCount(5),
)
if err != nil {
return err
}
queue.Push(ctx, taskqueue.Task{ID: "task-1", Payload: []byte(`{"key":"value"}`)})
queue.Start(ctx)
Tasks are stored in Redis as a list (main queue) and a sorted set (processing set with timestamps). Worker failures are detected via a configurable timeout on the processing set entries.
Index ¶
- Variables
- type Executor
- type Option
- type Payload
- type Queue
- func (q *Queue) Name() string
- func (q *Queue) ProcessingCount(ctx context.Context) (int64, error)
- func (q *Queue) Push(ctx context.Context, tasks ...Task) error
- func (q *Queue) QueueLength(ctx context.Context) (int64, error)
- func (q *Queue) RecoverStale(ctx context.Context, maxAge time.Duration) (int, error)
- func (q *Queue) Start(ctx context.Context) error
- func (q *Queue) Stop() error
- type Task
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrQueueAlreadyRunning = errors.New("taskqueue: queue is already running") ErrQueueNotRunning = errors.New("taskqueue: queue is not running") ErrNilClient = errors.New("taskqueue: redis client is nil") ErrNilExecutor = errors.New("taskqueue: task executor is nil") ErrEmptyQueueKey = errors.New("taskqueue: queue key is empty") ErrMaxAgeTooSmall = errors.New("taskqueue: maxAge must be greater than execTimeout") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Queue)
func WithBufferSize ¶
func WithExecTimeout ¶
func WithPollInterval ¶
func WithWorkerCount ¶
Click to show internal directories.
Click to hide internal directories.