How start celery worker in Django project

Question:

I have a Django project with the directory structure mentioned below. I am trying to use Celery for running tasks in the background. I have facing some trouble while running the worker. Whenever I issue the following command, I get an error.

Command

$ celery -A tasks worker --loglevel=info 

From the projectdirectory where manage.py resides

ModuleNotFoundError: No module named ‘tasks’

From the projectdirectory where celery.py resides

ModuleNotFoundError: No module named ‘tasks’

From the appdirectory where tasks.py resides

AttributeError: module ‘tasks’ has no attribute ‘celery’

Project Structure

project
    |-- app
         |-- admin.py
         |-- apps.py
         |-- __init__.py
         |-- models.py
         |-- tasks.py
         |-- tests.py
         |-- urls.py
         |-- views.py
    |-- project
            |-- celery.py
            |-- settings.py
            |-- __init__.py
            |-- urls.py
            |-- wsgi.py
    |-- manage.py
Asked By: arush1836

||

Answers:

You should use project name to start celery. Since your celery.py located inside project directory you need to run from the project’s root directory following:

celery -A project worker --loglevel=info 

Instead of

celery -A tasks worker --loglevel=info 

Check example here.

Answered By: neverwalkaloner
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.