Search code examples
pythonwindowspython-2.7celerybeat

Periodic task not working when using crontab at given hour and minute


I'm trying to run a periodic task defined in a simple python script:

@periodic_task(run_every=crontab(hour=7, minute=43))
def every_day_morning():
    print("Good Morning!")

This is the command line I'm using:

python -m celery -A tasks beat

When I use crontab(minute='*') it works perfectly but, when I try it like:

@periodic_task(run_every=crontab(hour=7, minute=43))

it doesn't work (the task doesn't run).

I'm using python 2.7, and celery 3.1.16 in Windows 8.1.


Solution

  • check your timezone! utc0 is celery default timezone!

    U need to change it to your system timezone, like this:

    pp = Celery(...)
    app.conf.update(...
            CELERY_TIMEZONE = 'Asia/Shanghai'   # set timezone in here
            )