django 项目中的 Celery 异步任务。它是如何运作的?
我需要在我的 Django 项目中运行长时间的任务。决定使用 celery 和 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/。它可以是什么?也许我错过了什么?
I need in my django project run long tasks. Desided to use celery with redis as broker. Installed redis runs:
The server is now ready to accept connections on port 6379
Than I install django-celery, configure:
import djcelery
djcelery.setup_loader()
BROKER_HOST = "localhost"
BROKER_PORT = 6379 #redis
BROKER_USER = "guest"
BROKER_PASSWORD = "guest"
BROKER_VHOST = "/"
and run it:
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...
my example task look like:
from celery.decorators import task
@task()
def add(x, y):
return x + y
now I try to run it in shell:
In [3]: from message.tasks import add
In [4]: r=add.delay(2, 5)
it wait very long and render Traceback http://dpaste.com/555939/. What it can be? Maybe I miss something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
缺少
BROKER_BACKEND
设置。以下是使用 Redis 的示例配置:The
BROKER_BACKEND
setting is missing. Here is a example config for using Redis:不知道这是什么,但我知道 RabbitMQ 是 Celery 和 Django 的推荐代理。我让它运行起来,它就像一个魅力。为什么不尝试一下呢?
Don't know what this is, but I do know that RabbitMQ is the recommended broker for Celery and Django. I have it running and it works like a charm. Why not give that one a go?