[GH-ISSUE #315] [FEATURE REQUEST] Provide the task ID to the task object when using the handler callback. #2158

Closed
opened 2026-03-15 19:27:39 +03:00 by kerem · 2 comments
Owner

Originally created by @pbarnum on GitHub (Aug 20, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/315

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
I would like to get the ID of the task currently being processed in the handler's callback function.

Describe alternatives you've considered
Adding our own ID to the task object and getting it through the payload.

Additional context
I would like to reference the resource (task) generated for logging purposes. Currently, the Task interface only exposes Type() string and Payload() []byte.

Originally created by @pbarnum on GitHub (Aug 20, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/315 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** No. **Describe the solution you'd like** I would like to get the ID of the task currently being processed in the handler's callback function. **Describe alternatives you've considered** Adding our own ID to the task object and getting it through the payload. **Additional context** I would like to reference the resource (task) generated for logging purposes. Currently, the `Task` interface only exposes `Type() string` and `Payload() []byte`.
kerem 2026-03-15 19:27:39 +03:00
Author
Owner

@crossworth commented on GitHub (Aug 20, 2021):

Does GetTaskID solves your problem?

func HandleEmailDeliveryTask(ctx context.Context, t *asynq.Task) error {
    id, ok := GetTaskID(ctx)
    return nil
}
<!-- gh-comment-id:903003117 --> @crossworth commented on GitHub (Aug 20, 2021): Does [`GetTaskID`](https://pkg.go.dev/github.com/hibiken/asynq?utm_source=godoc#GetTaskID) solves your problem? ```go func HandleEmailDeliveryTask(ctx context.Context, t *asynq.Task) error { id, ok := GetTaskID(ctx) return nil } ```
Author
Owner

@pbarnum commented on GitHub (Aug 20, 2021):

Oh gosh yes it does! I don't know how I missed that. Thank you 👍

<!-- gh-comment-id:903004954 --> @pbarnum commented on GitHub (Aug 20, 2021): Oh gosh yes it does! I don't know how I missed that. Thank you 👍
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#2158
No description provided.