diff --git a/config.go b/config.go index c481de2..921cb24 100644 --- a/config.go +++ b/config.go @@ -24,6 +24,8 @@ type GormConfig struct { type QueueConfig struct { EnableQueue bool + Concurrency int + Queues map[string]int } type CacheConfig struct { diff --git a/queue.go b/queue.go index 905a6ed..70de9cd 100644 --- a/queue.go +++ b/queue.go @@ -27,22 +27,32 @@ func (q *Queuemux) AddWork(pattern string, work Asynqtask) { q.themux.HandleFunc(pattern, work) } -// RunQueueserver starts the queue server with predefined configurations and handles tasks using the assigned ServeMux. +// RunQueueserver starts the queue server with the given configuration and handles tasks using the assigned ServeMux. // Configures the queue server with concurrency limits and priority-based queue management. // Logs and terminates the program if the server fails to run. -func (q *Queuemux) RunQueueserver() { +func (q *Queuemux) RunQueueserver(config QueueConfig) { redisAddr := fmt.Sprintf("%v:%v", os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT")) + queues := config.Queues + if queues == nil { + queues = map[string]int{ + "critical": 6, + "default": 3, + "low": 1, + } + } + + concurrency := config.Concurrency + if concurrency <= 0 { + concurrency = 10 + } + srv := asynq.NewServer( asynq.RedisClientOpt{Addr: redisAddr}, - asynq.Config{Concurrency: 10, - // Optionally specify multiple queues with different priority. - Queues: map[string]int{ - "critical": 6, - "default": 3, - "low": 1, - }, + asynq.Config{ + Concurrency: concurrency, + Queues: queues, }, )