我使用djcelery创建了一个基于类的定期任务,以便向客户端发送电子邮件。任务正在执行操作并在从shell调用时发送电子邮件,但在使用crontab时,我将KeyError作为“Schedule.tasks.run”。我添加了以下设置并创建了任务:
import os
import djcelery
djcelery.setup_loader()
BROKER_URL = 'django://'
BROKER_HOST = "localhost"
BROKER_PORT = 5672
BROKER_USER = "guest"
BROKER_PASSWORD = "guest"
BROKER_VHOST = "/"
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERYBEAT_SCHEDULE = {
"runs-every-30-seconds": {
"task": "schedules.tasks.EndingDrawslotScheduler.run",
"schedule": timedelta(seconds=30),
"args": (16, 16)
},
}
app.conf.timezone = 'UTC'
INSTALLED_APPS = ('djcelery',
'kombu.transport.django',)
邮件正文的全部内容是:
{'utc': True, 'callbacks': None, 'id': '6ad19ff8-9825-4d54-a8b2-0a8322fc9fb1',
'args': [], 'taskset': None, 'retries': 0, 'timelimit': (None, None),
'kwargs': {}, 'expires': None, 'errbacks': None, 'chord': None, 'task':
'schedules.tasks.run', 'eta': None} (262b)
追踪(最近一次呼叫最后一次):
文件“/home/s/proj/env/lib/python3.5/site-packages/celery/worker/consumer.py”,第465行,在on_task_received策略中[类型_](消息,正文, KeyError:'schedules.tasks.run'