Search code examples
pythoncelerycelery-task

deferred execution celery task


I want to put a task to celery, but I want the task is executed after 30 seconds instead of executed immediately.

For example:

@celery.task
def task():
    # waiting 30 seconds
    do something....

I can use it to make it: sleep(30), but is there any better solution?


Solution

  • The best way would be for that task's task to be to schedule the real task in 30 seconds. Something like that:

    @celery.task
    def task():
        RealTask.apply_async(countdown=30)