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
JavaScript
x
2
1
$ celery -A tasks worker --loglevel=info
2
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
JavaScript
1
18
18
1
project
2
|-- app
3
|-- admin.py
4
|-- apps.py
5
|-- __init__.py
6
|-- models.py
7
|-- tasks.py
8
|-- tests.py
9
|-- urls.py
10
|-- views.py
11
|-- project
12
|-- celery.py
13
|-- settings.py
14
|-- __init__.py
15
|-- urls.py
16
|-- wsgi.py
17
|-- manage.py
18
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:
JavaScript
1
2
1
celery -A project worker --loglevel=info
2
Instead of
JavaScript
1
2
1
celery -A tasks worker --loglevel=info
2
Check example here.