繁体   English   中英

特定时间的Django Celery定期任务

[英]Django Celery Periodic Task at specific time

我在项目中使用celery==4.1.1 在我的settings.py ,我有以下内容:

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')
    }
}

CELERY_BEAT_SCHEDULE提到的第二项任务运行良好。 但是,第一个任务mathematica.core.tasks.another_test是一个返回字符串的简单函数,它不在指定的时间00:45 (45 minutes past midnight) 我尝试了每天在给定时间运行函数的多种方法,但未能达到相同的效果。

请提出达到相同结果的方法/提示。

'automatic_daily_report': {
            'task': 'tasks.daily_reports',
            'schedule': crontab(hour=0, minute=0),
            'args': None
        }


@shared_task()
def daily_reports():
    print("Mid- Night")

上面的代码为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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