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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With