Merge pull request #2 from Selly-Modules/update-retry-config
update retry config
This commit is contained in:
commit
21c2ce0592
|
@ -1,6 +1,10 @@
|
||||||
package queue
|
package queue
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hibiken/asynq"
|
||||||
|
)
|
||||||
|
|
||||||
// Config ...
|
// Config ...
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -13,7 +17,8 @@ type Config struct {
|
||||||
Concurrency int
|
Concurrency int
|
||||||
Priority ConfigPriority
|
Priority ConfigPriority
|
||||||
|
|
||||||
TaskTimeout time.Duration
|
TaskTimeout time.Duration
|
||||||
|
RetryDelayFunc asynq.RetryDelayFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigRedis ...
|
// ConfigRedis ...
|
||||||
|
|
15
instance.go
15
instance.go
|
@ -50,6 +50,13 @@ func initServer(redisConn asynq.RedisClientOpt, cfg Config) *asynq.ServeMux {
|
||||||
cfg.Priority.Low = 1
|
cfg.Priority.Low = 1
|
||||||
cfg.Priority.StrictMode = false
|
cfg.Priority.StrictMode = false
|
||||||
}
|
}
|
||||||
|
retryDelayFunc := cfg.RetryDelayFunc
|
||||||
|
if retryDelayFunc == nil {
|
||||||
|
// Default delay in 10s
|
||||||
|
retryDelayFunc = func(n int, e error, t *asynq.Task) time.Duration {
|
||||||
|
return 10 * time.Second
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init server
|
// Init server
|
||||||
server := asynq.NewServer(redisConn, asynq.Config{
|
server := asynq.NewServer(redisConn, asynq.Config{
|
||||||
|
@ -61,11 +68,7 @@ func initServer(redisConn asynq.RedisClientOpt, cfg Config) *asynq.ServeMux {
|
||||||
},
|
},
|
||||||
StrictPriority: cfg.Priority.StrictMode,
|
StrictPriority: cfg.Priority.StrictMode,
|
||||||
|
|
||||||
// TODO:
|
RetryDelayFunc: retryDelayFunc,
|
||||||
// This is default option, retry after 10s, will add to config later
|
|
||||||
RetryDelayFunc: func(n int, e error, t *asynq.Task) time.Duration {
|
|
||||||
return 10 * time.Second
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Init mux server
|
// Init mux server
|
||||||
|
@ -112,5 +115,5 @@ func initClient(redisConn asynq.RedisClientOpt) *asynq.Client {
|
||||||
|
|
||||||
// GetInstance ...
|
// GetInstance ...
|
||||||
func GetInstance() Instance {
|
func GetInstance() Instance {
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue