This is my project structure:
fj_project
|-- fj
| |-- celerybeat.pid
| |-- celerybeat-schedule
| |-- celeryconfig.pyc
| |-- fe
| | |-- admin.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- tasks.py
| | |-- tests.py
| | |-- views.py
| |-- FeJa
| | |-- celeryconfig.pyc
| | |-- __init__.py
| | |-- settings
| | | |-- base.py
| | | |-- celeryconfig.py
| | | |-- __init__.py
| | | |-- local.py
| | | |-- production.py
| | | |-- tasks.py
| | | `-- test.py
| | |-- urls.py
| | |-- wsgi.py
| |-- fj.sqlite3
| |-- __init__.py
| |-- manage.py
| |-- site-media
| `-- templates
| |-- 400.html
|-- Makefile
`-- requirements
|-- local.txt
-- production.txt
I start celery from the settings directory. And it starts but doesn't add the tasks mentioned in the fe directory. This is my celeryconfig file:
from __future__ import absolute_import
from celery import Celery
from datetime import timedelta
app = Celery('fj',
broker='amqp://',
backend='amqp://',
include=['tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
)
if __name__ == '__main__':
app.start()
I am unable to figure out how to make celery discover tasks in all the directories and sub-directories. Please help.
You can autodscover tasks by invoking autodiscover_tasks() on an instance of Celery class:
app.autodiscover_tasks(['fe'])
First argument is a list of packages to search and keyword argument "related_name" can contain name of a module holding tasks (default is "tasks").
List of packages to search can be django's INSTALLED_APPS list.
Here the documentation for autodiscover_tasks()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.