我正在为Celery / RabbitMQ / Django创建一个测试场景。浏览/阅读类似我的各种帖子后,我发现这一个,最接近,但仍然没有帮助我。我有#34; ImportError:没有名为tasks的模块"执行芹菜工人时出错。
芹菜:3.1.5(不是dj芹菜) Django:1.5.5
testcele/ (project name)
mycelery/ (myapp)
__init__
tasks
testcele/
__init__
celery_task
settings
from __future__ import absolute_import
import os
from celery import Celery, task, current_task
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testcele.settings')
app = Celery('testcele', backend='amqp', broker='amqp://guest@localhost//',
include=['tasks'])
if __name__ == '__main__':
app.start()
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
from __future__ import absolute_import
from .celery_task import app as celery_app
from __future__ import absolute_import
from celery import Celery, task, current_task, shared_task
@shared_task()
def create_models():
.
.
.
我正在跑步:"芹菜工人-A testcele -l INFO",在" testcele /"子目录。我也尝试从testcele / testcel子目录运行,从testcele / mycelery运行,替换" testcele"关于芹菜工人命令与"任务"或者" mycelery"。显然,这会产生其他错误。
我缺少什么?
谢谢里卡多
答案 0 :(得分:8)
尝试在__init__.py
文件夹中添加mycelery
文件,使其成为模块。如果这不起作用,请在定义app
时指定任务。像这样:
app = Celery('testcele', backend='amqp', broker='amqp://guest@localhost//',
include=['mycelery.tasks'])