我需要在我的django项目中运行长任务。决定使用芹菜与redis作为经纪人。已安装的redis运行:
服务器现在已准备好接受端口6379上的连接
比安装django-celery,配置:
import djcelery
djcelery.setup_loader()
BROKER_HOST = "localhost"
BROKER_PORT = 6379 #redis
BROKER_USER = "guest"
BROKER_PASSWORD = "guest"
BROKER_VHOST = "/"
并运行它:
python manage.py celeryd -l DEBUG
[...]
[2011-06-18 10:31:37,913: DEBUG/MainProcess] Starting thread Timer...
[2011-06-18 10:31:37,914: DEBUG/MainProcess] Starting thread Consumer...
[2011-06-18 10:31:37,914: WARNING/MainProcess] celery@greg... has started.
[2011-06-18 10:31:37,914: DEBUG/MainProcess] Consumer: Re-establishing connection to the broker...
我的示例任务看起来像:
from celery.decorators import task
@task()
def add(x, y):
return x + y
现在我尝试在shell中运行它:
In [3]: from message.tasks import add
In [4]: r=add.delay(2, 5)
等待很长时间并渲染Traceback http://dpaste.com/555939/。它可以是什么?也许我错过了什么?
答案 0 :(得分:2)
缺少BROKER_BACKEND
设置。以下是使用Redis的示例配置:
import djcelery
djcelery.setup_loader()
CELERY_RESULT_BACKEND = 'database'
BROKER_BACKEND = 'redis'
BROKER_HOST = 'localhost'
BROKER_PORT = 6379
BROKER_VHOST = '1'
答案 1 :(得分:0)
不知道这是什么,但我知道RabbitMQ是Celery和Django推荐的经纪人。我让它运行,它就像一个魅力。为什么不放手一搏?