[GH-ISSUE #808] [FEATURE REQUEST] [BUG] PostEnqueueFunc -> When Error occur, info is nil and we dont have way to access task #2424

Open
opened 2026-03-15 20:25:42 +03:00 by kerem · 4 comments
Owner

Originally created by @abhi9720 on GitHub (Jan 27, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/808

Originally assigned to: @hibiken on GitHub.

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

I have created a new periodic task manager and registered a post-enqueue function with it. However, due to some issue such as a task ID conflict, an error occurred and the taskinfo became nil. Now, how to access the task in the post method to determine which task caused the error.

Describe the solution you'd like

  1. Just Like PreEnqueueFunc func(task *Task, opts []Option), If an error occurs, we can pass the task to a function similar to the PreEnqueueFunc func else pass TaskInfo.

Describe alternatives you've considered

Additional context

Originally created by @abhi9720 on GitHub (Jan 27, 2024). Original GitHub issue: https://github.com/hibiken/asynq/issues/808 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** I have created a new periodic task manager and registered a post-enqueue function with it. However, due to some issue such as a task ID conflict, an error occurred and the taskinfo became nil. Now, **how to access the task in the post method to determine which task caused the error.** **Describe the solution you'd like** 1. Just Like PreEnqueueFunc func(task *Task, opts []Option), If an error occurs, we can pass the task to a function similar to the PreEnqueueFunc func else pass TaskInfo. **Describe alternatives you've considered** **Additional context**
Author
Owner

@kamikazechaser commented on GitHub (Jan 28, 2024):

which task caused the error

Are you talking about an error which is encountered in a task handler?

You can use a asynq.MiddlewareFunc which returns an asynq.Handler. In that you can ProcessTask and see if any error or panic occurs and dump the task id, payload e.t.c.

<!-- gh-comment-id:1913511786 --> @kamikazechaser commented on GitHub (Jan 28, 2024): > which task caused the error Are you talking about an error which is encountered in a task handler? You can use a `asynq.MiddlewareFunc` which returns an `asynq.Handler`. In that you can `ProcessTask` and see if any error or panic occurs and dump the task id, payload e.t.c.
Author
Owner

@abhi9720 commented on GitHub (Jan 28, 2024):

@kamikazechaser

I am talking about PostEnqueueFunc, when taskId conflict happens, I get an error of task id conflict, but I have no info about which task is in the post-enqueue function.

<!-- gh-comment-id:1913554060 --> @abhi9720 commented on GitHub (Jan 28, 2024): @kamikazechaser I am talking about PostEnqueueFunc, when taskId conflict happens, I get an error of task id conflict, but I have no info about which task is in the post-enqueue function.
Author
Owner

@kamikazechaser commented on GitHub (Jan 29, 2024):

That is intended behavior, whenever an error occurs anywhere in the "Run" chain a nil value is returned in place of the return type (a pointer), in this case it happens in the Enqueue method. I personally don't see this as a bug but you definitely have less info to work with in the event of an error.

It could make sense to enrich the error messages in the Enqueue method instead. Would that suffice?

<!-- gh-comment-id:1914055339 --> @kamikazechaser commented on GitHub (Jan 29, 2024): That is intended behavior, whenever an error occurs anywhere in the "Run" chain a nil value is returned in place of the return type (a pointer), in this case it happens in the Enqueue method. I personally don't see this as a bug but you definitely have less info to work with in the event of an error. It could make sense to enrich the error messages in the Enqueue method instead. Would that suffice?
Author
Owner

@abhi9720 commented on GitHub (Jan 29, 2024):

@kamikazechaser, ya something like that which help us to get access to error of that task.

<!-- gh-comment-id:1915012630 --> @abhi9720 commented on GitHub (Jan 29, 2024): @kamikazechaser, ya something like that which help us to get access to error of that task.
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#2424
No description provided.