5

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: 3.1.5 (not dj-celery) 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.

What I am missing?

Thanks, Ricardo

1 Answer 1

8

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:

app = Celery('testcele', backend='amqp', broker='amqp://guest@localhost//',
                include=['mycelery.tasks'])
Sign up to request clarification or add additional context in comments.

2 Comments

the 'init.py' file is indeed in the mycelery app folder. Since it's empty, I did not include it in the question (I just edited it to show it).
include=['mycelery.tasks'] instead of include=['tasks'] ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.