问题描述
Celery Beat无法使用crontab计划任务。它在随机时间安排。有时,它每隔一分钟安排一次。有时每两分钟一次,等等。
在配置的时间"schedule": crontab(hour='*/1')
和将任务发送给工作人员的时间之间没有关系!
不知道这是怎么回事。
这是我的celery_test.py:
from kombu import Queue,Exchange
from celery import Celery,shared_task,group,chord
from celery.schedules import crontab
app = Celery('celery_demo',broker='amqp://abcduser:abcdpassword@localhost/abcd_vhost',backend='rpc://',include=['celery_demo.tasks'])
app.conf.beat_schedule = {
"trigger-call_publisher": {
"task": "celery_demo.tasks.call_publisher","schedule": crontab(hour='*/1')
以下是我的task.py:
import sys
sys.path.append("..")
from celery_demo.celery_test import app
@app.task
def call_publisher():
print("Say Hello")
if __name__ == '__main__':
call_publisher.delay()
}
}
以下是这样的输出,其中每分钟发送一次任务:
解决方法
我认为让dor每小时运行一次,或者您只用一分钟:
crontab(minute='*/60')
或小时+分钟:
crontab(minute=0,hour='*/1')