Celery,Django,Heroku - ImportError:没有名为tasks的模块

时间:2013-04-15 13:41:40

标签: django heroku celery django-celery djcelery

我正在尝试使用IronMQ运行芹菜并在Heroku上的Django项目中缓存,但我收到以下内容:

2013-04-14T22:29:17.479887+00:00 app[celeryd.1]: ImportError: No module named tasks

我做错了什么?以下是我的相关代码和djcelery,我的应用程序都在已安装的应用程序中:

要求(兔子AMQP在那里,因为我在IronMQ之前尝试过):

Django==1.5.1
amqp==1.0.11
anyjson==0.3.3
billiard==2.7.3.27
boto==2.8.0
celery==3.0.18
dj-database-url==0.2.1
django-celery==3.0.17
django-storages==1.1.8
gunicorn==0.17.2
iron-cache==0.2.0
iron-celery==0.3.1
iron-core==1.0.2
iron-mq==0.4
iso8601==0.1.4
kombu==2.5.10
psycopg2==2.4.6
python-dateutil==2.1
pytz==2013b
requests==1.2.0
six==1.3.0
wsgiref==0.1.2

PROCFILE:

web: gunicorn myapp.wsgi
celeryd: celery -A tasks worker --loglevel=info -E

设定:

BROKER_URL = 'ironmq://'
CELERY_RESULT_BACKEND = 'ironcache://'

import djcelery
import iron_celery

djcelery.setup_loader()

任务:

from celery import task
@task()
def batchAdd(result_length, result_amount):

视图:

from app import tasks
r = batchAdd.delay(result_length, result_amount)
return HttpResponse(r.task_id)

还试过(在VIEWS中):

from tasks import batchAdd
r = batchAdd.delay(result_length, result_amount)
return HttpResponse(r.task_id)

并尝试(在VIEWS中):

from app.tasks import batchAdd
r = batchAdd.delay(result_length, result_amount)
return HttpResponse(r.task_id)

这也是我的结构:

projectname
--app
----__init__.py
----__init__.pyc
----admin.py
----admin.pyc
----forms.py
----forms.pyc
----models.py
----models.pyc
----tasks.py
----tests.py
----views.py
----views.pyc
--manage.py
--Procfile
--projectname
----__init__.py
----__init__.pyc
----settings.py
----settings.pyc
----static
----templates
----urls.py
----urls.pyc
----wsgi.py
----wsgi.pyc
--requirements.txt

2 个答案:

答案 0 :(得分:3)

您是否尝试通过manage.py加载芹菜?

python manage.py celery worker --loglevel=info

答案 1 :(得分:0)

您不能只使用以下方式运行芹菜:

celery -A tasks worker --loglevel=info -E

Celery需要带有-A选项的celeryconfig文件。你应该按照djcelery docs中的描述运行芹菜。

python manage.py celery worker --loglevel=info

此外,您应该将views.py修复为

from app.tasks import batchAdd