1

每个人。当我从 django shell 运行以下代码时,我Django==1.5遇到django-celery==3.0.11 了问题 error: [Errno 61] Connection refused

from data_warehouse.tasks import add
add.delay(4,4) 

设置.py

INSTALLED_APPS += ('djcelery')
# Settings for Celery Task Scheduler
BROKER_URL = 'mongodb://'
import djcelery
djcelery.setup_loader()

data_warehouse.tasks(从教程复制)

from celery.task import task
@task()
def add(x, y):
    return x + y

当我运行 python manage.py celery worker -l info 我得到

 -------------- celery@Atthaphongs-MacBook-Air.local v3.0.16 (Chiastic Slide)
---- **** ----- 
--- * ***  * -- [Configuration]
-- * - **** --- . broker:      mongodb://localhost//
- ** ---------- . app:         default:0x10f215810 (djcelery.loaders.DjangoLoader)
- ** ---------- . concurrency: 4 (processes)
- ** ---------- . events:      OFF (enable -E to monitor this worker)
- ** ---------- 
- *** --- * --- [Queues]
-- ******* ---- . celery:      exchange:celery(direct) binding:celery
--- ***** ----- 
[Tasks]
  . data_warehouse.tasks.add
/Users/atthaphong/VirtualEnvs/report/lib/python2.7/site-packages/djcelery/loaders.py:132: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
  warnings.warn("Using settings.DEBUG leads to a memory leak, never "
[2013-03-23 01:38:22,999: WARNING/MainProcess] /Users/atthaphong/VirtualEnvs/report/lib/python2.7/site-packages/djcelery/loaders.py:132: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
  warnings.warn("Using settings.DEBUG leads to a memory leak, never "
[2013-03-23 01:38:23,000: WARNING/MainProcess] celery@Atthaphongs-MacBook-Air.local ready.
[2013-03-23 01:38:23,002: INFO/MainProcess] consumer: Connected to mongodb://localhost//.
/Users/atthaphong/VirtualEnvs/report/lib/python2.7/site-packages/pymongo/mongo_client.py:274: UserWarning: database name in URI is being ignored. If you wish to authenticate to admin, you must provide a username and password.
  "and password." % (db,))
[2013-03-23 01:38:23,005: WARNING/MainProcess] /Users/atthaphong/VirtualEnvs/report/lib/python2.7/site-packages/pymongo/mongo_client.py:274: UserWarning: database name in URI is being ignored. If you wish to authenticate to admin, you must provide a username and password.
  "and password." % (db,))

当我尝试使用带有此代码的 python shell 运行任务时

from celery import Celery
celery = Celery('tasks', broker='mongodb://')
celery.conf.CELERY_RESULT_BACKEND = "mongodb"
@celery.task
def add(x, y):
    return x + y

我得到这个预期的错误。

[2013-03-23 02:04:30,218: ERROR/MainProcess] Received unregistered task of type     'tasks.add'.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you are using relative imports?

问题可能来自 Celery 实例没有调用正确的代理 url,但我还没有弄清楚。你对此有什么想法吗?

解决了!!只需添加

BROKER_TRANSPORT = 'mongodb'

到 settings.py

4

0 回答 0