Unique recurring task #376
-
Hi everyone, for my project I need to have a task run at regular intervals to go through the database and check which entries are due for refresh. I don't want every worker instance to run this, and would like the task to be assigned like any other "normal" task. For this I need to create a task that may only exist once, but I am stuck on how to facilitate that, as there are N frontend servers and N workers and no single one is supposed to be an authority. Is this possible? How can I create a task exactly once? Thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
@Unkn0wnCat Thank you for opening a discussion! Have you taken a look at this wiki page on periodic-tasks (https://github.com/hibiken/asynq/wiki/Periodic-Tasks)? Update: // This ensures there's only one task with ID "foo" in the default queue, and the task will be kept in the queue for x duration after the task has been successfully processed.
client.Enqueue(task, asynq.TaskID("foo"), asynq.Retention(x)) Also, check issue #369 to see if there's alternative solution available (e.g. We may decide to add another variant of |
Beta Was this translation helpful? Give feedback.
@Unkn0wnCat Thank you for opening a discussion!
Have you taken a look at this wiki page on periodic-tasks (https://github.com/hibiken/asynq/wiki/Periodic-Tasks)?
Update:
TLDR; If you have multiple
Scheduler
s running to create periodic tasks but want to avoid enqueueing duplicate tasks, try usingTaskID
andRetention
options.Also, check issue #369 to see if there's alternative solution available (e.g. We may decide to add another variant of
Unique
option …