export priority value

This commit is contained in:
Nam Huynh 2021-11-30 23:02:50 +07:00
parent 61c1ac19a4
commit ed3d068e80
3 changed files with 12 additions and 7 deletions

View File

@ -2,7 +2,7 @@ package queue
// Constant
const (
priorityCritical = "critical"
priorityDefault = "default"
priorityLow = "low"
PriorityCritical = "critical"
PriorityDefault = "default"
PriorityLow = "low"
)

View File

@ -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,

View File

@ -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