[GH-ISSUE #183] [FEATURE REQUEST] Recurring scheduled tasks using a CRON schedule #60

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

Originally created by @oliverproud on GitHub (Jul 16, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/183

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.
I need a task to be enqueued at the same time each day.

Describe the solution you'd like
To be able to schedule a task to be enqueued using a CRON schedule. This task will then be enqueued repeatedly, based on the CRON schedule. E.g. Task to send an email is enqueued at midnight, everyday.

Describe alternatives you've considered
I have tried using GoCraft/Work and their periodic enqueuer but I had issues with using the library and getting the UI to work.

Additional context
The enqueueAt function is almost perfect but I just need to be able to have that enqueue happen at the same time each day.

Also, thank you for the library and the extensive documentation. It has been really great to use!

Thanks

Originally created by @oliverproud on GitHub (Jul 16, 2020). Original GitHub issue: https://github.com/hibiken/asynq/issues/183 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** I need a task to be enqueued at the same time each day. **Describe the solution you'd like** To be able to schedule a task to be enqueued using a CRON schedule. This task will then be enqueued repeatedly, based on the CRON schedule. E.g. Task to send an email is enqueued at midnight, everyday. **Describe alternatives you've considered** I have tried using [GoCraft/Work](https://github.com/gocraft/work) and their [periodic enqueuer](https://github.com/gocraft/work#periodic-enqueueing-cron) but I had issues with using the library and getting the UI to work. **Additional context** The enqueueAt function is almost perfect but I just need to be able to have that enqueue happen at the same time each day. Also, thank you for the library and the extensive documentation. It has been really great to use! Thanks
kerem 2026-03-02 05:18:19 +03:00
Author
Owner

@hibiken commented on GitHub (Jul 17, 2020):

@oliverproud Thank you for opening this issue!

I see a lot of similar libraries implement this feature.
I'll look into this over the weekend and will update this thread with an initial proposal.

<!-- gh-comment-id:659848014 --> @hibiken commented on GitHub (Jul 17, 2020): @oliverproud Thank you for opening this issue! I see a lot of similar libraries implement this feature. I'll look into this over the weekend and will update this thread with an initial proposal.
Author
Owner

@oliverproud commented on GitHub (Jul 17, 2020):

@hibiken That's great, thank you for your reply!

<!-- gh-comment-id:659960962 --> @oliverproud commented on GitHub (Jul 17, 2020): @hibiken That's great, thank you for your reply!
Author
Owner

@hibiken commented on GitHub (Jul 20, 2020):

Hi @oliverproud , here's my initial idea on what the API would look like, let me know if you have any thoughts or feedback!
I'm still trying to figure out the semantics around duplicate task. For example, if there are multiple server running the same cron configuration, should we deduplicate?

Initial Proposal

Introduce a new Cron type to register periodic tasks.
This cron scheduler can be run as part of Asynq server.

// NewCron creates a new cron scheduler.
cron := asynq.NewCron()
// Register creates an entry in crontab to schedule a periodic task.
// Method signature is: Register(schedule string, task *Task, opts ...Option)
cron.Register("* * * * *", task1)
cron.Register(""12 * * * *", task2, asynq.Retry(10), asynq.Timeout(15*time.Minute))

srv := asynq.NewServer(r, asynq.Config{
     // Register cron scheduler as part of asynq server.
    Cron: cron,
})

if err := srv.Run(handler); err != nil {
     log.Fatal(err)
}

Open Questions

  • How to handle duplicate tasks if there are multiple Asynq server running with the same cron configuration.
<!-- gh-comment-id:661036295 --> @hibiken commented on GitHub (Jul 20, 2020): Hi @oliverproud , here's my initial idea on what the API would look like, let me know if you have any thoughts or feedback! I'm still trying to figure out the semantics around duplicate task. For example, if there are multiple server running the same cron configuration, should we deduplicate? ## Initial Proposal Introduce a new `Cron` type to register periodic tasks. This cron scheduler can be run as part of Asynq server. ```go // NewCron creates a new cron scheduler. cron := asynq.NewCron() // Register creates an entry in crontab to schedule a periodic task. // Method signature is: Register(schedule string, task *Task, opts ...Option) cron.Register("* * * * *", task1) cron.Register(""12 * * * *", task2, asynq.Retry(10), asynq.Timeout(15*time.Minute)) srv := asynq.NewServer(r, asynq.Config{ // Register cron scheduler as part of asynq server. Cron: cron, }) if err := srv.Run(handler); err != nil { log.Fatal(err) } ``` ## Open Questions - How to handle duplicate tasks if there are multiple Asynq server running with the same cron configuration.
Author
Owner

@oliverproud commented on GitHub (Jul 20, 2020):

Hi @hibiken, proposal looks great to me. In regards to your open question, that is outside my area of expertise so I'm going to have to defer to you.

Thanks for your response!

<!-- gh-comment-id:661245479 --> @oliverproud commented on GitHub (Jul 20, 2020): Hi @hibiken, proposal looks great to me. In regards to your open question, that is outside my area of expertise so I'm going to have to defer to you. Thanks for your response!
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#60
No description provided.