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

后端 未结 5 1573
忘掉有多难
忘掉有多难 2020-11-29 02:32

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

5条回答
  •  眼角桃花
    2020-11-29 03:08

    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

提交回复
热议问题