[英]Errors running celery with Django
這是我的項目結構:
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
我從設置目錄開始芹菜。 它會啟動,但不會添加fe目錄中提到的任務。 這是我的celeryconfig文件:
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()
我無法弄清楚如何使celery發現所有目錄和子目錄中的任務。 請幫忙。
您可以通過在Celery類的實例上調用autodiscover_tasks()來自動發現任務:
app.autodiscover_tasks(['fe'])
第一個參數是要搜索的軟件包的列表,關鍵字參數“ related_name”可以包含保存任務的模塊的名稱(默認為“ tasks”)。
可以搜索的軟件包列表可以是django的INSTALLED_APPS列表。
這里是autodiscover_tasks()的文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.