From ed3d068e80bf38642eea2ac989a30638e946cf2a Mon Sep 17 00:00:00 2001 From: Nam Huynh Date: Tue, 30 Nov 2021 23:02:50 +0700 Subject: [PATCH] export priority value --- constant.go | 6 +++--- instance.go | 6 +++--- task.go | 7 ++++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/constant.go b/constant.go index 668c77d..4c9ce48 100644 --- a/constant.go +++ b/constant.go @@ -2,7 +2,7 @@ package queue // Constant const ( - priorityCritical = "critical" - priorityDefault = "default" - priorityLow = "low" + PriorityCritical = "critical" + PriorityDefault = "default" + PriorityLow = "low" ) diff --git a/instance.go b/instance.go index 2e50444..5462e6b 100644 --- a/instance.go +++ b/instance.go @@ -52,9 +52,9 @@ func initServer(redisConn asynq.RedisClientOpt, cfg Config) *asynq.ServeMux { server := asynq.NewServer(redisConn, asynq.Config{ Concurrency: cfg.Concurrency, Queues: map[string]int{ - priorityCritical: cfg.Priority.Critical, - priorityDefault: cfg.Priority.Default, - priorityLow: cfg.Priority.Low, + PriorityCritical: cfg.Priority.Critical, + PriorityDefault: cfg.Priority.Default, + PriorityLow: cfg.Priority.Low, }, StrictPriority: cfg.Priority.StrictMode, diff --git a/task.go b/task.go index ba5b3e0..aaa86d5 100644 --- a/task.go +++ b/task.go @@ -5,11 +5,16 @@ import ( ) // RunTask ... -func (i Instance) RunTask(typename string, payload []byte, retryTimes int) (*asynq.TaskInfo, error) { +func (i Instance) RunTask(typename string, payload []byte, priority string, retryTimes int) (*asynq.TaskInfo, error) { // Create task and options task := asynq.NewTask(typename, payload) options := make([]asynq.Option, 0) + // Priority + if priority != PriorityCritical && priority != PriorityDefault && priority != PriorityLow { + priority = PriorityDefault + } + // Retry times if retryTimes < 0 { retryTimes = 0