2020-05-28 21:28:14 +08:00
|
|
|
// Copyright 2020 Kentaro Hibino. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package asynq
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-11-04 06:55:23 +08:00
|
|
|
asynqcontext "github.com/hibiken/asynq/internal/context"
|
2020-05-28 21:28:14 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetTaskID extracts a task ID from a context, if any.
|
|
|
|
//
|
|
|
|
// ID of a task is guaranteed to be unique.
|
|
|
|
// ID of a task doesn't change if the task is being retried.
|
|
|
|
func GetTaskID(ctx context.Context) (id string, ok bool) {
|
2021-11-04 06:55:23 +08:00
|
|
|
return asynqcontext.GetTaskID(ctx)
|
2020-05-28 21:28:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRetryCount extracts retry count from a context, if any.
|
|
|
|
//
|
|
|
|
// Return value n indicates the number of times associated task has been
|
|
|
|
// retried so far.
|
|
|
|
func GetRetryCount(ctx context.Context) (n int, ok bool) {
|
2021-11-04 06:55:23 +08:00
|
|
|
return asynqcontext.GetRetryCount(ctx)
|
2020-05-28 21:28:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetMaxRetry extracts maximum retry from a context, if any.
|
|
|
|
//
|
|
|
|
// Return value n indicates the maximum number of times the assoicated task
|
|
|
|
// can be retried if ProcessTask returns a non-nil error.
|
|
|
|
func GetMaxRetry(ctx context.Context) (n int, ok bool) {
|
2021-11-04 06:55:23 +08:00
|
|
|
return asynqcontext.GetMaxRetry(ctx)
|
2020-05-28 21:28:14 +08:00
|
|
|
}
|
2020-09-08 01:54:42 +08:00
|
|
|
|
|
|
|
// GetQueueName extracts queue name from a context, if any.
|
|
|
|
//
|
|
|
|
// Return value qname indicates which queue the task was pulled from.
|
|
|
|
func GetQueueName(ctx context.Context) (qname string, ok bool) {
|
2021-11-04 06:55:23 +08:00
|
|
|
return asynqcontext.GetQueueName(ctx)
|
2020-09-08 01:54:42 +08:00
|
|
|
}
|