[GH-ISSUE #653] How to prevent duplicate scheduler task registe across multiple Asynq server nodes #323

Closed
opened 2026-03-02 05:20:28 +03:00 by kerem · 5 comments
Owner

Originally created by @wwwfeng on GitHub (May 4, 2023).
Original GitHub issue: https://github.com/hibiken/asynq/issues/653

How to prevent duplicate scheduler task registe across multiple Asynq server nodes

Originally created by @wwwfeng on GitHub (May 4, 2023). Original GitHub issue: https://github.com/hibiken/asynq/issues/653 How to prevent duplicate scheduler task registe across multiple Asynq server nodes
kerem closed this issue 2026-03-02 05:20:28 +03:00
Author
Owner

@wwwfeng commented on GitHub (May 4, 2023):

I have the following code, but if multiple instances of asynq are started, the scheduled task may be registered to Redis repeatedly. How to avoid this?

....
task := asynq.NewTask(pb.SchedulerType_STAT_CAR_UPTIME.String(), nil)
entryID, err := l.svcCtx.Scheduler.Register(crontab, task)
....
<!-- gh-comment-id:1534069095 --> @wwwfeng commented on GitHub (May 4, 2023): I have the following code, but if multiple instances of asynq are started, the scheduled task may be registered to Redis repeatedly. How to avoid this? ``` .... task := asynq.NewTask(pb.SchedulerType_STAT_CAR_UPTIME.String(), nil) entryID, err := l.svcCtx.Scheduler.Register(crontab, task) .... ```
Author
Owner

@aaps3579 commented on GitHub (May 8, 2023):

@wwwfeng Yes. If multiple instances of scheduler are started, task will be scheduled multiple times.
Refer to this thread https://github.com/hibiken/asynq/issues/395 for solution.

<!-- gh-comment-id:1537854209 --> @aaps3579 commented on GitHub (May 8, 2023): @wwwfeng Yes. If multiple instances of scheduler are started, task will be scheduled multiple times. Refer to this thread https://github.com/hibiken/asynq/issues/395 for solution.
Author
Owner

@wwwfeng commented on GitHub (May 8, 2023):

@wwwfeng Yes. If multiple instances of scheduler are started, task will be scheduled multiple times. Refer to this thread #395 for solution.

Thanks for your reply. I checked the documentation and used asynq.TaskID and asynq.Retention, and it seems to be effective. Does this mean that the same scheduled task will only be written once within the time set by asynq.Retention?

<!-- gh-comment-id:1538041639 --> @wwwfeng commented on GitHub (May 8, 2023): > @wwwfeng Yes. If multiple instances of scheduler are started, task will be scheduled multiple times. Refer to this thread #395 for solution. Thanks for your reply. I checked the documentation and used ` asynq.TaskID` and ` asynq.Retention`, and it seems to be effective. Does this mean that the same scheduled task will only be written once within the time set by asynq.Retention?
Author
Owner

@aaps3579 commented on GitHub (May 8, 2023):

Retention time dictates for how much long task is gonna stay in the system. And any task enqueued with same taskID will give asynq.ErrTaskIDConflict error.

<!-- gh-comment-id:1538071628 --> @aaps3579 commented on GitHub (May 8, 2023): Retention time dictates for how much long task is gonna stay in the system. And any task enqueued with same taskID will give asynq.ErrTaskIDConflict error.
Author
Owner

@wwwfeng commented on GitHub (May 8, 2023):

Retention time dictates for how much long task is gonna stay in the system. And any task enqueued with same taskID will give asynq.ErrTaskIDConflict error.

Thank you so much for your response.I understand now.

<!-- gh-comment-id:1538076971 --> @wwwfeng commented on GitHub (May 8, 2023): > Retention time dictates for how much long task is gonna stay in the system. And any task enqueued with same taskID will give asynq.ErrTaskIDConflict error. Thank you so much for your response.I understand now.
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#323
No description provided.