Documentation
¶
Index ¶
- Constants
- type Config
- type Enqueuer
- func (e *Enqueuer) EnqueueBody(jobName string, payload interface{}) (string, error)
- func (e *Enqueuer) EnqueueBodyDelayedWithRetry(jobName string, delay time.Duration, payload interface{}, ...) (string, error)
- func (e *Enqueuer) EnqueueBodyIn(jobName string, delay time.Duration, payload interface{}) (string, error)
- func (e *Enqueuer) EnqueueBodyUnique(jobName string, payload interface{}) (string, error)
- func (e *Enqueuer) EnqueueBodyWithRetry(jobName string, payload interface{}, opts work.RetryOptions) (string, error)
- type Job
- type JobHandler
- type JobOption
- type WorkerPool
Constants ¶
const BodyKey = "body"
BodyKey is the args key used to carry the JSON-encoded payload.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Namespace string // Redis key namespace (e.g. "myapp-work").
RedisURL string // "host:port" or "redis://:password@host:port".
RedisDB int // Redis database number (0–15); ignored for redis:// URLs.
Concurrency uint // Number of concurrent workers (default 10).
}
Config holds the Redis connection and worker pool configuration.
type Enqueuer ¶
type Enqueuer struct {
// contains filtered or unexported fields
}
Enqueuer wraps work.Enqueuer with a simpler, JSON-centric interface.
func NewEnqueuer ¶
NewEnqueuer creates an Enqueuer backed by the given Redis pool and namespace.
func (*Enqueuer) EnqueueBody ¶
EnqueueBody marshals payload to JSON and enqueues an immediate job. It returns the new job's ID.
func (*Enqueuer) EnqueueBodyDelayedWithRetry ¶
func (e *Enqueuer) EnqueueBodyDelayedWithRetry(jobName string, delay time.Duration, payload interface{}, opts work.RetryOptions) (string, error)
EnqueueBodyDelayedWithRetry marshals payload and enqueues with both a delay and retry options.
func (*Enqueuer) EnqueueBodyIn ¶
func (e *Enqueuer) EnqueueBodyIn(jobName string, delay time.Duration, payload interface{}) (string, error)
EnqueueBodyIn marshals payload to JSON and enqueues with a delay.
func (*Enqueuer) EnqueueBodyUnique ¶
EnqueueBodyUnique marshals payload and enqueues only if no identical job is already queued. Returns ("", nil) when a duplicate is detected.
func (*Enqueuer) EnqueueBodyWithRetry ¶
func (e *Enqueuer) EnqueueBodyWithRetry(jobName string, payload interface{}, opts work.RetryOptions) (string, error)
EnqueueBodyWithRetry marshals payload and enqueues with retry options.
type JobHandler ¶
JobHandler processes jobs of a specific type. PerformJob receives the JSON-encoded body string from the job args.
type JobOption ¶
type JobOption func(*work.JobOptions)
JobOption is a functional option that configures a work.JobOptions value.
func WithBackoff ¶
WithBackoff sets a custom backoff function for retries.
func WithHighPriority ¶
func WithHighPriority() JobOption
WithHighPriority is a convenience alias for WithPriority(10).
func WithLowPriority ¶
func WithLowPriority() JobOption
WithLowPriority is a convenience alias for WithPriority(1).
func WithMaxConcurrency ¶
WithMaxConcurrency limits how many instances of this job may run at once.
func WithMaxFails ¶
WithMaxFails sets the maximum number of failures before the job is sent to the dead queue.
func WithPriority ¶
WithPriority sets the job's scheduling priority.
func WithSkipDead ¶
WithSkipDead controls whether failed jobs bypass the dead queue.
type WorkerPool ¶
type WorkerPool interface {
AddJobHandlers(handlers ...JobHandler)
AddRecurringJobs(cronTaskMap map[string]string)
Start(ctx context.Context)
Stop()
}
WorkerPool manages job handlers, middleware, and periodic schedules.
func NewWorkerPool ¶
func NewWorkerPool(redisPool *redis.Pool, namespace string, concurrency uint) WorkerPool
NewWorkerPool creates a pool with logging and panic-recovery middleware.