-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue_options.go
69 lines (61 loc) · 1.68 KB
/
queue_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package asyncer
import (
"time"
"github.com/hibiken/asynq"
)
// WithQueues sets the queues.
// It panics if the sum of concurrency is not equal to the concurrency
// set in the config.
// If you want to increase the concurrency of a queue, you can use
// asyncer.WithQueueConcurrency before this option.
func WithQueues(queues map[string]int) QueueServerOption {
return func(cnf *asynq.Config) {
// check if sum of concurrency is equal to the concurrency
// set in the config.
var sum int
for _, v := range queues {
sum += v
}
if sum != cnf.Concurrency {
panic("sum of concurrency is not equal to the concurrency set in the config")
}
cnf.Queues = queues
}
}
// WithQueueName sets the queue name.
func WithQueueName(name string) QueueServerOption {
return func(cnf *asynq.Config) {
cnf.Queues = map[string]int{
name: cnf.Concurrency,
}
}
}
// WithQueueConcurrency sets the queue concurrency.
func WithQueueConcurrency(concurrency int) QueueServerOption {
return func(cnf *asynq.Config) {
cnf.Concurrency = concurrency
for k := range cnf.Queues {
cnf.Queues[k] = concurrency
}
}
}
// WithQueueShutdownTimeout sets the queue shutdown timeout.
func WithQueueShutdownTimeout(timeout time.Duration) QueueServerOption {
return func(cnf *asynq.Config) {
cnf.ShutdownTimeout = timeout
}
}
// WithQueueLogLevel sets the queue log level.
func WithQueueLogLevel(level string) QueueServerOption {
return func(cnf *asynq.Config) {
cnf.LogLevel = castToAsynqLogLevel(level)
}
}
// WithQueueLogger sets the queue logger.
func WithQueueLogger(logger asynq.Logger) QueueServerOption {
return func(cnf *asynq.Config) {
if logger != nil {
cnf.Logger = logger
}
}
}