queue

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueClosed = errors.New("queue is closed")
)

Functions

This section is empty.

Types

type JobBatch

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

JobBatch represents a collection of jobs to run concurrently.

func NewBatch

func NewBatch(jobs ...contract.Job) *JobBatch

NewBatch constructs a JobBatch.

func (*JobBatch) Handle

func (b *JobBatch) Handle() error

Handle runs the batch.

func (*JobBatch) Name

func (b *JobBatch) Name() string

Name returns the job name.

func (*JobBatch) OnFail

func (b *JobBatch) OnFail(fn func(err error)) *JobBatch

OnFail sets the callback to execute if any job fails.

func (*JobBatch) OnSuccess

func (b *JobBatch) OnSuccess(fn func()) *JobBatch

OnSuccess sets the callback to execute when all jobs complete successfully.

type JobChain

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

JobChain executes a series of jobs sequentially. If one fails, the chain stops.

func NewChain

func NewChain(jobs ...contract.Job) *JobChain

NewChain constructs a new JobChain.

func (*JobChain) Handle

func (c *JobChain) Handle() error

Handle executes the chain of jobs.

func (*JobChain) Name

func (c *JobChain) Name() string

Name returns the job name.

type MemoryQueue

type MemoryQueue struct {
	BackoffFactor time.Duration // Custom backoff multiplier (defaults to time.Second)
	// contains filtered or unexported fields
}

MemoryQueue is an in-memory, channel-backed implementation of the contract.Queue interface. It is ideal for local development, testing, and single-instance deployments.

func NewMemoryQueue

func NewMemoryQueue(capacity int) *MemoryQueue

NewMemoryQueue creates a new MemoryQueue with the specified buffer capacity.

func (*MemoryQueue) Close

func (q *MemoryQueue) Close() error

Close gracefully shuts down the queue and waits for workers to finish.

func (*MemoryQueue) DeleteFailedJob

func (q *MemoryQueue) DeleteFailedJob(id string) error

DeleteFailedJob permanently removes a failed job by its ID.

func (*MemoryQueue) GetFailedJobs

func (q *MemoryQueue) GetFailedJobs() ([]contract.FailedJob, error)

GetFailedJobs lists failed jobs in the memory queue.

func (*MemoryQueue) GetStats

func (q *MemoryQueue) GetStats() (contract.QueueStats, error)

GetStats retrieves overview counters of the queue state.

func (*MemoryQueue) Push

func (q *MemoryQueue) Push(job contract.Job) error

Push adds a job to the back of the queue immediately.

func (*MemoryQueue) PushDelayed

func (q *MemoryQueue) PushDelayed(job contract.Job, delay time.Duration) error

PushDelayed dispatches a job to the queue, delaying execution by a set duration. In this simple memory queue, we spawn a goroutine to wait, then push.

func (*MemoryQueue) RetryJob

func (q *MemoryQueue) RetryJob(id string) error

RetryJob re-queues a failed job by its ID.

func (*MemoryQueue) StartWorkers

func (q *MemoryQueue) StartWorkers(workers int)

StartWorkers starts a pool of background worker goroutines to process jobs.

type RedisQueue

type RedisQueue struct {
	BackoffFactor time.Duration // Custom backoff multiplier (defaults to time.Second)
	// contains filtered or unexported fields
}

RedisQueue implements contract.Queue using a Redis List as the backing store.

func NewRedisQueue

func NewRedisQueue(addr, password string, db int, registry map[string]func() contract.Job) *RedisQueue

NewRedisQueue creates a new Redis-backed queue. registry maps job names to constructor functions so deserialization can produce the correct concrete Job type.

func (*RedisQueue) DeleteFailedJob

func (q *RedisQueue) DeleteFailedJob(id string) error

DeleteFailedJob permanently removes a failed job by its ID.

func (*RedisQueue) GetFailedJobs

func (q *RedisQueue) GetFailedJobs() ([]contract.FailedJob, error)

GetFailedJobs lists failed jobs in the Redis queue.

func (*RedisQueue) GetStats

func (q *RedisQueue) GetStats() (contract.QueueStats, error)

GetStats retrieves overview counters of the queue state.

func (*RedisQueue) Push

func (q *RedisQueue) Push(job contract.Job) error

Push serializes the job and pushes it to the head of the Redis list.

func (*RedisQueue) PushDelayed

func (q *RedisQueue) PushDelayed(job contract.Job, delay time.Duration) error

PushDelayed adds a job to a Redis Sorted Set, scored by its future execution timestamp.

func (*RedisQueue) RetryJob

func (q *RedisQueue) RetryJob(id string) error

RetryJob re-queues a failed job by its ID.

func (*RedisQueue) StartWorkers

func (q *RedisQueue) StartWorkers(workers int)

StartWorkers spawns N worker goroutines that each block on BRPOP, waiting for jobs.

Jump to

Keyboard shortcuts

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