get queue configurations from config in cup
This commit is contained in:
parent
75ddca3e7d
commit
b757aef6b1
2 changed files with 21 additions and 9 deletions
|
|
@ -24,6 +24,8 @@ type GormConfig struct {
|
||||||
|
|
||||||
type QueueConfig struct {
|
type QueueConfig struct {
|
||||||
EnableQueue bool
|
EnableQueue bool
|
||||||
|
Concurrency int
|
||||||
|
Queues map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheConfig struct {
|
type CacheConfig struct {
|
||||||
|
|
|
||||||
26
queue.go
26
queue.go
|
|
@ -27,22 +27,32 @@ func (q *Queuemux) AddWork(pattern string, work Asynqtask) {
|
||||||
q.themux.HandleFunc(pattern, work)
|
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.
|
// Configures the queue server with concurrency limits and priority-based queue management.
|
||||||
// Logs and terminates the program if the server fails to run.
|
// 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"))
|
redisAddr := fmt.Sprintf("%v:%v", os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT"))
|
||||||
|
|
||||||
srv := asynq.NewServer(
|
queues := config.Queues
|
||||||
asynq.RedisClientOpt{Addr: redisAddr},
|
if queues == nil {
|
||||||
asynq.Config{Concurrency: 10,
|
queues = map[string]int{
|
||||||
// Optionally specify multiple queues with different priority.
|
|
||||||
Queues: map[string]int{
|
|
||||||
"critical": 6,
|
"critical": 6,
|
||||||
"default": 3,
|
"default": 3,
|
||||||
"low": 1,
|
"low": 1,
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
concurrency := config.Concurrency
|
||||||
|
if concurrency <= 0 {
|
||||||
|
concurrency = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := asynq.NewServer(
|
||||||
|
asynq.RedisClientOpt{Addr: redisAddr},
|
||||||
|
asynq.Config{
|
||||||
|
Concurrency: concurrency,
|
||||||
|
Queues: queues,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue