How to add an execution delay to a task?
edhowler opened this issue ยท 5 comments
Hi, thanks for this library!
How can I add a task that is executed 10 seconds after it was sent? Is there a simple workaround, in the case it is not implemented?
I think I got it, that's a queue configuration, directly in AWS console. I wish I could set it individually for each task.
At the risk of missing the point, why don't you add sleep(10)
to the task?
Hey, thanks for the idea. That would work, but with the drawback that the worker would be busy for more time than needed.
@edhowler hi! Sorry for such a delay in response. Glad you've found the lib useful.
I've never implemented this time of behavior myself, so I may be not the best person to advise. Anyway, AWS seems to have a feature called delay-queues โ I think you can use it to delay visibility of the tasks for the worker. I guess you can create a delay queue and send messages to this queue to delay them.
This feature is something that could be very useful. The aforementioned delay-queues
only allow to configure the delay for the whole queue, but a very standard task is to delay certain tasks by different durations. For example, send a letter to the user after 10 minutes of his registration. Or send a push notification reminder in an hour. Sleep
surely won't work in this scenario. Having a cron job every minute to match some conditions in DB is also a huge overhead.
P.S. If anybody found a suitable alternative, please let me know.