From 3bdd6ce7ff4812291a4b8d457f7b57e142778daa Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 10 Aug 2022 17:17:34 +0700 Subject: [PATCH] update retry config --- config.go | 9 +++++++-- instance.go | 15 +++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 60ce5fe..780dbec 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,10 @@ package queue -import "time" +import ( + "time" + + "github.com/hibiken/asynq" +) // Config ... type Config struct { @@ -13,7 +17,8 @@ type Config struct { Concurrency int Priority ConfigPriority - TaskTimeout time.Duration + TaskTimeout time.Duration + RetryDelayFunc asynq.RetryDelayFunc } // ConfigRedis ... diff --git a/instance.go b/instance.go index c05c628..0f12628 100644 --- a/instance.go +++ b/instance.go @@ -50,6 +50,13 @@ func initServer(redisConn asynq.RedisClientOpt, cfg Config) *asynq.ServeMux { cfg.Priority.Low = 1 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 server := asynq.NewServer(redisConn, asynq.Config{ @@ -61,11 +68,7 @@ func initServer(redisConn asynq.RedisClientOpt, cfg Config) *asynq.ServeMux { }, StrictPriority: cfg.Priority.StrictMode, - // TODO: - // 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 - }, + RetryDelayFunc: retryDelayFunc, }) // Init mux server @@ -112,5 +115,5 @@ func initClient(redisConn asynq.RedisClientOpt) *asynq.Client { // GetInstance ... func GetInstance() Instance { - return instance + return instance }