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 project
directory where manage.py
resides
ModuleNotFoundError: No module named ‘tasks’
From the project
directory where celery.py
resides
ModuleNotFoundError: No module named ‘tasks’
From the app
directory 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
Advertisement
Answer
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.