Reputation: 791
I am using celery==4.1.1
in my project. In my settings.py
, I have the following:
from celery.schedules import crontab
CELERY_BROKER_URL = "redis://127.0.0.1:6379/1"
CELERY_TIMEZONE = 'Asia/Kolkata'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = "redis://127.0.0.1:6379/1"
CELERY_BEAT_SCHEDULE = {
'task-number-one': {
'task': 'mathematica.core.tasks.another_test',
'schedule': crontab(minute=45, hour=00)
},
'task-number-two': {
'task': 'mathematica.core.tasks.test',
'schedule': crontab(hour='*/1')
}
}
The second task mentioned in CELERY_BEAT_SCHEDULE
is running perfectly. However, the first task mathematica.core.tasks.another_test
which is a simple function returning a string is not running at the specified time, 00:45 (45 minutes past midnight)
. I have tried a number of ways to run a function at a given time each day but failed to achieve the same.
Please suggest ways/hints to achieve the same results.
Upvotes: 1
Views: 1641
Reputation: 1281
'automatic_daily_report': {
'task': 'tasks.daily_reports',
'schedule': crontab(hour=0, minute=0),
'args': None
}
@shared_task()
def daily_reports():
print("Mid- Night")
Above code worked for me.
Upvotes: 2