我按照指南设置了RabbitMQ,安装Celery,并通过shell执行文件。我现在正在尝试学习如何使用相同的文件执行周期性任务,但无论我做什么,我都会收到此错误:两个任务/配置都在根目录中。
[2015-07-02 07:56:33,928: ERROR/MainProcess] Received unregistered task of type
'tasks.scrape'.The message has been ignored and discarded.
File "/home/apps/django/env/local/lib/python2.7/site- packages/celery/worker/consumer.py", line 455, in on_task_received strategies[name](message, body,
KeyError: 'tasks.scrape'
tasks.py
from celery import Celery
app = Celery('tasks', backend='amqp', broker='amqp://guest@localhost//')
app.config_from_object('celeryconfig')
@app.task(name='scrape-odds')
def scrape(x,y):
return x + y
celeryconfig.py
from datetime import timedelta
from celery.schedules import crontab
CELERY_IMPORTS = ("tasks" )
CELERY_ENABLE_UTC = True
CELERY_TIMEZONE = 'UTC'
CELERYBEAT_SCHEDULE = {
'scrape-odds': {
'task': 'tasks.scrape',
'schedule': timedelta(seconds=30),
'args': (16, 16)
},
}
答案 0 :(得分:1)
由于某种原因,你给了你的任务一个不同的名字:“scrape-odds”。你应该使用那个名字。