get queue configurations from config in cup

This commit is contained in:
Zeni Kim 2026-05-18 22:34:37 -05:00
parent 75ddca3e7d
commit b757aef6b1
2 changed files with 21 additions and 9 deletions

View file

@ -24,6 +24,8 @@ type GormConfig struct {
type QueueConfig struct {
EnableQueue bool
Concurrency int
Queues map[string]int
}
type CacheConfig struct {

View file

@ -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"))
srv := asynq.NewServer(
asynq.RedisClientOpt{Addr: redisAddr},
asynq.Config{Concurrency: 10,
// Optionally specify multiple queues with different priority.
Queues: map[string]int{
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: concurrency,
Queues: queues,
},
)