[GH-ISSUE #456] [FEATURE REQUEST] Is there any way to do some specific action before periodic task enqueue? #208

Closed
opened 2026-03-02 05:19:38 +03:00 by kerem · 7 comments
Owner

Originally created by @ChihSeanHsu on GitHub (May 8, 2022).
Original GitHub issue: https://github.com/hibiken/asynq/issues/456

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.
As title, I'm wondering is there any option or handler before periodic task enqueue?

Describe the solution you'd like
Maybe, we can solve this case just like error-handling

Additional context
IMO, we can implement this function in Enqueue part, not only for periodic task.

Originally created by @ChihSeanHsu on GitHub (May 8, 2022). Original GitHub issue: https://github.com/hibiken/asynq/issues/456 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** As title, I'm wondering is there any option or handler before periodic task enqueue? **Describe the solution you'd like** Maybe, we can solve this case just like [error-handling](https://github.com/hibiken/asynq/wiki/Periodic-Tasks#error-handling) **Additional context** IMO, we can implement this function in Enqueue part, not only for periodic task.
kerem 2026-03-02 05:19:38 +03:00
Author
Owner

@hibiken commented on GitHub (May 9, 2022):

@ChihSeanHsu thank you for creating a feature request.

What kind of action do you need to perform before enqueueing a task? I want to understand the motivation.

<!-- gh-comment-id:1120596456 --> @hibiken commented on GitHub (May 9, 2022): @ChihSeanHsu thank you for creating a feature request. What kind of action do you need to perform before enqueueing a task? I want to understand the motivation.
Author
Owner

@ChihSeanHsu commented on GitHub (May 9, 2022):

@hibiken Thanks for your prompt response.
We want to have a metrics to monitor the periodic enqueue count or some other actions (Currently, I have no another idea).
Although, we can just make this metrics by processing task part, but I just wonder is there any pre-action way not post-action.

<!-- gh-comment-id:1120625470 --> @ChihSeanHsu commented on GitHub (May 9, 2022): @hibiken Thanks for your prompt response. We want to have a metrics to monitor the periodic enqueue count or some other actions (Currently, I have no another idea). Although, we can just make this metrics by processing task part, but I just wonder is there any pre-action way not post-action.
Author
Owner

@hibiken commented on GitHub (May 10, 2022):

I see. Actually, now that I'm thinking about it, maybe it makes sense to allow users to provide callbacks before and after enqueue happens on Scheduler.

Something like:

type SchedulerOpts struct {
    // PreEnqueueFunc, if provided, is called before a task gets enqueued by Scheduler.
    // The callback function should return quickly to not block the current thread.
    PreEnqueueFunc func(task *Task, opts []Option)

    // PostEnqueueFunc, if provided, is called after a task gets enqueued by Scheduler.
    // The callback function should return quickly to not block the current thread.
    PostEnqueueFunc func(info *TaskInfo, err error)

   // ... other options

   // Deprecated: Use PostEnqueueFunc instead
   ErrorHandlerFunc func(task *Task, opts []Option, err error)
}
<!-- gh-comment-id:1122346998 --> @hibiken commented on GitHub (May 10, 2022): I see. Actually, now that I'm thinking about it, maybe it makes sense to allow users to provide callbacks before and after enqueue happens on Scheduler. Something like: ```go type SchedulerOpts struct { // PreEnqueueFunc, if provided, is called before a task gets enqueued by Scheduler. // The callback function should return quickly to not block the current thread. PreEnqueueFunc func(task *Task, opts []Option) // PostEnqueueFunc, if provided, is called after a task gets enqueued by Scheduler. // The callback function should return quickly to not block the current thread. PostEnqueueFunc func(info *TaskInfo, err error) // ... other options // Deprecated: Use PostEnqueueFunc instead ErrorHandlerFunc func(task *Task, opts []Option, err error) }
Author
Owner

@ChihSeanHsu commented on GitHub (May 10, 2022):

@hibiken Great.
Thanks for your help!
What will the road map be about this small feature?
Or can I just submit a PR about it?

<!-- gh-comment-id:1122517923 --> @ChihSeanHsu commented on GitHub (May 10, 2022): @hibiken Great. Thanks for your help! What will the road map be about this small feature? Or can I just submit a PR about it?
Author
Owner

@hibiken commented on GitHub (May 10, 2022):

@ChihSeanHsu Feel free to open a PR if you have bandwidth to work on it. Thanks :)

<!-- gh-comment-id:1122999785 --> @hibiken commented on GitHub (May 10, 2022): @ChihSeanHsu Feel free to open a PR if you have bandwidth to work on it. Thanks :)
Author
Owner

@ChihSeanHsu commented on GitHub (May 22, 2022):

Hi @hibiken
Here is the PR, and feel free to review it thanks.

<!-- gh-comment-id:1133836661 --> @ChihSeanHsu commented on GitHub (May 22, 2022): Hi @hibiken Here is the [PR](https://github.com/hibiken/asynq/pull/476), and feel free to review it thanks.
Author
Owner

@hibiken commented on GitHub (May 27, 2022):

Closed via #476. This feature will be included in the next release. Thank you @ChihSeanHsu !

<!-- gh-comment-id:1139893217 --> @hibiken commented on GitHub (May 27, 2022): Closed via #476. This feature will be included in the next release. Thank you @ChihSeanHsu !
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#208
No description provided.