简体   繁体   中英

Django Celery Periodic Task at specific time

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.

'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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM