我正在尝试使用 MongoDB 作为 Celery 的消息队列(在 Django 应用程序中)。当前的 Celery 开发版本 (2.2.0rc2) 应该让你这样做,但我似乎无法让任何工作人员接手我正在创建的任务。
版本:芹菜 v2.2.0rc3
mongodb 1.6.5
pymongo 1.9
django-celery 2.2.0rc2
在我的设置中,我有:
CELERY_RESULT_BACKEND = "mongodb"
CELERY_MONGODB_BACKEND_SETTINGS = {
# Shouldn't need these - defaults are correct.
"host": "localhost",
"port": 27017,
"database": "celery",
"taskmeta_collection": "messages",
}
BROKER_BACKEND = 'mongodb'
BROKER_HOST = "localhost"
BROKER_PORT = 27017
BROKER_USER = ""
BROKER_PASSWORD = ""
BROKER_VHOST = ""
import djcelery
djcelery.setup_loader()
我创建了一个测试 tasks.py 文件,如下所示:
from celery.decorators import task
@task()
def add(x, y):
return x + y
如果我在后台启动 celeryd,它似乎可以正常启动。然后我打开一个 python shell 并运行以下命令:
>>> from myapp.tasks import add
>>> result = add.delay(5,5)
>>> result
<AsyncResult: 7174368d-288b-4abe-a6d7-aeba987fa886>
>>> result.ready()
False
问题是没有工人接手任务。我错过了一个设置还是什么?如何将 celery 指向消息队列?