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

2.6k views Asked by At

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.

2

There are 2 answers

0
n3xtm3 On BEST ANSWER

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
        )
0
PKD On

Check your timezone by running command in terminal

timedatectl | grep "Timezone"

Update your celery app configuration

app = Celery()
app.conf.update(timezone='Asia/Kolkata')  # set your time zone here

Hope this helps