大家。使用Django==1.5
和django-celery==3.0.11
时遇到问题
当我从django shell
error: [Errno 61] Connection refused
from data_warehouse.tasks import add
add.delay(4,4)
settings.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