Celery ImportError:没有名为tasks的模块

时间:2022-01-20 19:17:00

I'm creating a test scenario for Celery/RabbitMQ/Django. After browsing/reading the various posts similar to mine, I found this one, the closest, but still does not help me. I'm having the "ImportError: no module named tasks" error when executing celery worker.

我正在为Celery / RabbitMQ / Django创建一个测试场景。浏览/阅读类似我的各种帖子后,我发现这一个,最接近,但仍然没有帮助我。我在执行芹菜工作时遇到“ImportError:no module named tasks”错误。

Celery: 3.1.5 (not dj-celery) Django: 1.5.5

芹菜:3.1.5(不是dj芹菜)Django:1.5.5

Project structure:

testcele/ (project name)
  mycelery/ (myapp)
    __init__
    tasks

  testcele/
    __init__
    celery_task
    settings

testcele/testcele/celery_task:

  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)

testcele/testcele/init.py:

  from __future__ import absolute_import
  from .celery_task import app as celery_app

mycelery/tasks.py:

  from __future__ import absolute_import
  from celery import Celery, task, current_task, shared_task


  @shared_task()
  def create_models():
    .
    .
    .

I'm running: "celery worker -A testcele -l INFO", at the "testcele/" sub-dir. I have also tried running from testcele/testcel sub-dir, from testcele/mycelery, replacing "testcele" on the celery worker command with "tasks" or "mycelery". Obviously, this gives other errors.

我正在跑步:“芹菜工人-A testcele -l INFO”,位于“testcele /”子目录。我也尝试从testcele / testcel子目录运行,从testcele / mycelery运行,用“tasks”或“mycelery”替换celery worker命令中的“testcele”。显然,这会产生其他错误。

What I am missing?

我错过了什么?

Thanks, Ricardo

1 个解决方案

#1


7  

Try adding a __init__.py file in your mycelery folder to make it a module. If that didn't work specify the tasks when defining your app. Like so:

尝试在mycelery文件夹中添加__init__.py文件,使其成为模块。如果这不起作用,请在定义应用时指定任务。像这样:

app = Celery('testcele', backend='amqp', broker='amqp://guest@localhost//',
                include=['mycelery.tasks'])

#1


7  

Try adding a __init__.py file in your mycelery folder to make it a module. If that didn't work specify the tasks when defining your app. Like so:

尝试在mycelery文件夹中添加__init__.py文件,使其成为模块。如果这不起作用,请在定义应用时指定任务。像这样:

app = Celery('testcele', backend='amqp', broker='amqp://guest@localhost//',
                include=['mycelery.tasks'])