django-eb-sqs-worker icon indicating copy to clipboard operation
django-eb-sqs-worker copied to clipboard

How to add an execution delay to a task?

Open edhowler opened this issue 4 years ago • 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?

edhowler avatar Apr 29 '21 07:04 edhowler

I think I got it, that's a queue configuration, directly in AWS console. I wish I could set it individually for each task.

edhowler avatar Apr 29 '21 08:04 edhowler

At the risk of missing the point, why don't you add sleep(10) to the task?

melvyn-apryl avatar May 22 '21 13:05 melvyn-apryl

Hey, thanks for the idea. That would work, but with the drawback that the worker would be busy for more time than needed.

edhowler avatar Jun 09 '21 16:06 edhowler

@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.

DataGreed avatar Jun 14 '21 23:06 DataGreed

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.

MrLightful avatar Apr 18 '22 12:04 MrLightful