みんな。Djangoシェルから次のコードを実行する
と、使用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シェルを使用してタスクを実行しようとしたとき
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 へ