按照“芹菜的第一步” 我有以下结构:
芹菜_
celery.py:
from celery import Celery
from config import celeryconfig
app = Celery('tasks', backend='rpc://', broker='pyamqp://')
app.config_from_object(celeryconfig)
celeryconfig.py
broker_url = 'pyamqp://'
result_backend = 'rpc://'
task_serializer = 'json'
result_serializer = 'json'
accept_content = ['json']
timezone = 'Europe/Oslo'
enable_utc = True
task_routes = {
'tasks.add': 'low-priority',
}
task_annotations = {
'tasks.add': {'rate_limit': '10/m'}
}
tasks.py:
from config.celery import app
@app.task
def add(x, y):
return x + y
run_tasks.py:
from tasks.tasks import add
res = add.delay(4,4)
a = res.get()
print(a)
这是一个非常简单的配置,但是当我运行run_tasks.py时,控制台显示错误:
....回溯(最近的最后一次通话): 文件“ /usr/lib/python3/dist-packages/celery/worker/consumer.py”,行 456,在on_task_received中 策略[名称](消息,正文, KeyError:“ tasks.tasks.add”
请帮帮我。怎么了?
答案 0 :(得分:0)
您需要将任务导入celery.py
/var/log/apache2/error.log