Documentation
¶
Overview ¶
Package queue provides explicit background jobs with typed handler registration, an inline sync driver for development, and a Redis (asynq) driver for production with retries, delays, and graceful drain.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HandlerFunc ¶
HandlerFunc processes one job payload.
type Option ¶
type Option func(*jobOptions)
Option customizes a single dispatch.
type Options ¶
type Options struct {
// Driver selects the backend: "sync" (default, executes jobs inline) or
// "redis" (asynq worker with retries and graceful drain).
Driver string
// RedisURL configures the redis driver, e.g. redis://localhost:6379/0.
RedisURL string
// Concurrency is the redis worker goroutine count, defaulting to 10.
Concurrency int
// Queues maps queue names to priorities; defaults to {"default": 1}.
Queues map[string]int
// ShutdownTimeout bounds the in-flight drain on stop, defaulting to 8s.
ShutdownTimeout time.Duration
// Logger store data used by this type.
Logger *slog.Logger
}
Options defines an implementation type used by this package.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue dispatches and processes background jobs.
func (*Queue) Handle ¶
func (q *Queue) Handle(name string, handler HandlerFunc)
Handle registers a raw payload handler for the named job. Register every handler before Start; later registrations are not picked up by a running worker.
type QueueStats ¶
type QueueStats struct {
// Name store data used by this type.
Name string `json:"name"`
// Pending store data used by this type.
Pending int `json:"pending"`
// Active store data used by this type.
Active int `json:"active"`
// Scheduled store data used by this type.
Scheduled int `json:"scheduled"`
// Retry store data used by this type.
Retry int `json:"retry"`
// Archived store data used by this type.
Archived int `json:"archived"`
// Completed store data used by this type.
Completed int `json:"completed"`
}
QueueStats reports the task counts of one named queue.
type Stats ¶
type Stats struct {
// Driver store data used by this type.
Driver string `json:"driver"`
// Queues store data used by this type.
Queues []QueueStats `json:"queues,omitempty"`
}
Stats reports the driver backing the queue and per-queue task counts. The sync driver executes jobs inline, so it reports no queues.