Documentation
¶
Index ¶
- Constants
- func Dispatch(q *queue.Queue, payload job.Job) error
- func DispatchBatch(q *queue.Queue, jobs []job.Job) error
- func DispatchBatchWithDelay(q *queue.Queue, jobs []job.Job, delay time.Duration) error
- func DispatchWithDelay(q *queue.Queue, payload job.Job, delay time.Duration) error
- func GetVersion() string
- func IsQueueOverloaded(q *queue.Queue) bool
- func RegisterJob(name string, constructor func() Job)
- func Shutdown(q *queue.Queue, ctx context.Context) error
- func StartWorker(q *queue.Queue, ctx context.Context, count int) error
- type Job
- type JobMetrics
- type Queue
- type QueueStats
Constants ¶
const DefaultShutdownTimeout = 5 * time.Second
const Version = "0.2.0"
Version represents the current version of GoQueue
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
Dispatch adds a single job to the queue for processing.
The job will be stored in the configured backend and processed by available workers.
Parameters:
- q: The queue to dispatch the job to
- payload: The job to be processed
Returns:
- nil on successful dispatch
- an error if dispatch fails
Dispatch adds a single job to the queue for processing (immediate execution).
func DispatchBatch ¶
DispatchBatch adds multiple jobs to the queue for processing.
All jobs will be stored in the configured backend and processed by available workers. This is more efficient than calling Dispatch multiple times for individual jobs.
Parameters:
- q: The queue to dispatch the jobs to
- jobs: Slice of jobs to be processed
Returns:
- nil on successful batch dispatch
- an error if batch dispatch fails
DispatchBatch adds multiple jobs to the queue for processing (immediate execution).
func DispatchBatchWithDelay ¶
DispatchBatchWithDelay adds multiple jobs to the queue for processing after a delay. Delay can be specified in seconds, minutes, or hours using time.Duration.
func DispatchWithDelay ¶
DispatchWithDelay adds a single job to the queue for processing after a delay. Delay can be specified in seconds, minutes, or hours using time.Duration.
func IsQueueOverloaded ¶
IsQueueOverloaded checks if the queue is currently experiencing high load.
The determination is based on the configured thresholds for job count and processing ratios. This can be used to implement backpressure mechanisms.
Parameters:
- q: The queue to check load status for
Returns:
- true if the queue is overloaded
- false if the queue is operating normally or if statistics collection is disabled
func RegisterJob ¶
RegisterJob registers a job type with the queue system to enable serialization/deserialization.
This must be called for each job type before using the queue. It associates a string name with a function that creates new instances of your job type.
Parameters:
- name: A unique string identifier for the job type
- constructor: A function that returns a new instance of the job type
func Shutdown ¶
Shutdown gracefully stops the queue, waiting for in-progress jobs to complete.
It will wait up to the timeout duration configured during queue creation for jobs to finish.
Parameters:
- q: The queue to shut down
- ctx: Context used for cancellation
Returns:
- nil if shutdown completes successfully
- an error if shutdown fails or times out
func StartWorker ¶
StartWorker launches worker goroutines to process jobs from the queue.
Workers will continue running until the provided context is cancelled.
Parameters:
- q: The queue to start workers for
- ctx: Context used for cancellation and shutdown
- count: Number of worker goroutines to start
Returns:
- Error if workers cannot be started
Types ¶
type JobMetrics ¶
type JobMetrics = config.JobMetrics
type Queue ¶
func NewQueue ¶
NewQueue creates a new queue with the specified name, configuration, and shutdown timeout.
Parameters:
- queueName: A unique identifier for the queue
- cfg: The queue configuration specifying backend, workers, retry policy, etc.
- shutdownTimeout: Maximum duration to wait for jobs to complete during shutdown
Returns:
- A new Queue instance and nil error on success
- nil and an error if queue creation fails
func NewQueueWithDefaults ¶
NewQueueWithDefaults creates a new queue with the specified name and configuration, using the default shutdown timeout.
This is a convenience function for when you don't need to specify a custom shutdown timeout.
Parameters:
- queueName: A unique identifier for the queue
- cfg: The queue configuration specifying backend, workers, retry policy, etc.
Returns:
- A new Queue instance and nil error on success
- nil and an error if queue creation fails
type QueueStats ¶
type QueueStats = stats.QueueStats
func GetQueueStats ¶
func GetQueueStats(q *queue.Queue) QueueStats
GetQueueStats returns current queue statistics and health metrics.
This includes job counts, processing rates, and health indicators. If statistics collection is disabled in the queue configuration, only basic health information is returned.
Parameters:
- q: The queue to get statistics for
Returns:
- QueueStats containing the current queue metrics
Directories
¶
Path | Synopsis |
---|---|
dlq
Package dlq provides the Dead Letter Queue (DLQ) interface for handling failed jobs.
|
Package dlq provides the Dead Letter Queue (DLQ) interface for handling failed jobs. |
internal
|
|
Package job provides the core job processing interfaces and types for the goqueue package.
|
Package job provides the core job processing interfaces and types for the goqueue package. |
Package middleware provides a flexible middleware system for customizing job processing behavior.
|
Package middleware provides a flexible middleware system for customizing job processing behavior. |
Package queue provides the core job queue functionality, including job dispatching, worker management, and queue lifecycle control.
|
Package queue provides the core job queue functionality, including job dispatching, worker management, and queue lifecycle control. |
Package worker provides job processing functionality through concurrent worker goroutines.
|
Package worker provides job processing functionality through concurrent worker goroutines. |