[GH-ISSUE #281] [QUESTION] Get Queue and Task Information in Queue Handler #2136

Closed
opened 2026-03-15 19:20:15 +03:00 by kerem · 1 comment
Owner

Originally created by @sujit-baniya on GitHub (Jun 16, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/281

Originally assigned to: @hibiken on GitHub.

In case of using same handler for different queues, is it possible to get the current queue and task information in the handler? If yes, how?

Originally created by @sujit-baniya on GitHub (Jun 16, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/281 Originally assigned to: @hibiken on GitHub. In case of using same handler for different queues, is it possible to get the current queue and task information in the handler? If yes, how?
kerem 2026-03-15 19:20:15 +03:00
Author
Owner

@hibiken commented on GitHub (Jun 16, 2021):

You can get that information from the context, use the following function to extract the data from the context:

Example:

func myHandler(ctx context, task *asynq.Task) error {
    qname, ok := asynq.GetQueueName(ctx)
    if !ok {
        log.Printf("Could not retrieve queue name from the context")
        qname = "unknown"
    }
   // use qname
}
<!-- gh-comment-id:862794539 --> @hibiken commented on GitHub (Jun 16, 2021): You can get that information from the context, use the following function to extract the data from the context: - [GetQueueName](https://pkg.go.dev/github.com/hibiken/asynq#GetMaxRetry) - [GetTaskID](https://pkg.go.dev/github.com/hibiken/asynq#GetMaxRetry) - [GetMaxRetry](https://pkg.go.dev/github.com/hibiken/asynq#GetMaxRetry) - [GetRetryCount](https://pkg.go.dev/github.com/hibiken/asynq#GetMaxRetry) Example: ```go func myHandler(ctx context, task *asynq.Task) error { qname, ok := asynq.GetQueueName(ctx) if !ok { log.Printf("Could not retrieve queue name from the context") qname = "unknown" } // use qname } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#2136
No description provided.