我在项目中使用的是 celery == 4.1.1 .在我的 settings.py 中,我有以下内容:
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') } }CELERY_BEAT_SCHEDULE 中提到的第二项任务运行良好.但是,第一个任务 mathematica.core.tasks.another_test 是一个返回字符串的简单函数,它不在指定的时间 00:45(午夜后45分钟)运行>.我尝试了每天在给定时间运行函数的多种方法,但未能实现相同的功能.
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")
上面的代码对我有用.
更多推荐
特定时间的Django Celery定期任务
发布评论