Celery: Delay “apply_async” execution

Celery apply_async is very useful feature from celery to execute some task asynchronously / non blocking.

There are 2 options to delay your task execution:

  • ETA (estimated time of arrival), which is you have to pass python datetime object to the argument.
    next_month = timezone.now() + timezone.timedelta(days=30)
    my_task_function.apply_async(args=*args, eta=next_month)
    

    Your celery task above will executed 1 month later.

  • Countdown, which is you have to pass integer (in seconds) to the argument.
    my_task_function.apply_async(args=*args, countdown=10)
    

    Your celery task above will executed after 10 seconds from now.

Reference: http://docs.celeryproject.org/en/latest/userguide/calling.html#eta-and-countdown

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s