繁体   English   中英

使用Django运行celery时出错

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM