Django:芹菜:芹菜问题的第一步

Django: Celery: First Steps With Celery Issues

我按照指南设置了 RabbitMQ,安装了 Celery,并通过 shell 执行了文件。我现在正在尝试学习如何使用同一个文件执行周期性任务,但是无论我做什么我都会收到此错误:tasks/config 都在根目录中。

[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)
    },
 }

出于某种原因,您为任务指定了不同的名称:"scrape-odds"。你应该使用那个名字。