How can I schedule a Task to execute at a specific time using celery?


Question

I've looked into PeriodicTask, but the examples only cover making it recur. I'm looking for something more like cron's ability to say "execute this task every Monday at 1 a.m."

1
16
1/2/2010 3:37:16 AM

Accepted Answer

The recently released version 1.0.3 supports this now, thanks to Patrick Altman!

Example:

from celery.task.schedules import crontab
from celery.decorators import periodic_task

@periodic_task(run_every=crontab(hour=7, minute=30, day_of_week="mon"))
def every_monday_morning():
    print("This runs every Monday morning at 7:30a.m.")

See the changelog for more information:

http://celeryproject.org/docs/changelog.html

28
5/16/2010 12:38:25 PM

Use

YourTask.apply_async(args=[some, args, here], eta=when)

And at the end of your task, reschedule it to the next time it should run.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon