github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/context.go (about) 1 // Copyright 2020 Kentaro Hibino. All rights reserved. 2 // Use of this source code is governed by a MIT license 3 // that can be found in the LICENSE file. 4 5 package asynq 6 7 import ( 8 "context" 9 10 asynqcontext "github.com/wfusion/gofusion/common/infra/asynq/pkg/context" 11 ) 12 13 // GetTaskID extracts a task ID from a context, if any. 14 // 15 // ID of a task is guaranteed to be unique. 16 // ID of a task doesn't change if the task is being retried. 17 func GetTaskID(ctx context.Context) (id string, ok bool) { 18 return asynqcontext.GetTaskID(ctx) 19 } 20 21 // GetRetryCount extracts retry count from a context, if any. 22 // 23 // Return value n indicates the number of times associated task has been 24 // retried so far. 25 func GetRetryCount(ctx context.Context) (n int, ok bool) { 26 return asynqcontext.GetRetryCount(ctx) 27 } 28 29 // GetMaxRetry extracts maximum retry from a context, if any. 30 // 31 // Return value n indicates the maximum number of times the associated task 32 // can be retried if ProcessTask returns a non-nil error. 33 func GetMaxRetry(ctx context.Context) (n int, ok bool) { 34 return asynqcontext.GetMaxRetry(ctx) 35 } 36 37 // GetQueueName extracts queue name from a context, if any. 38 // 39 // Return value queue indicates which queue the task was pulled from. 40 func GetQueueName(ctx context.Context) (queue string, ok bool) { 41 return asynqcontext.GetQueueName(ctx) 42 }