【问题标题】:Celery not finding/using celeryconfg芹菜没有找到/使用 celeryconfg
【发布时间】:2015-03-19 10:01:34
【问题描述】:

今天早上我的 google-fu 一定无法正常工作,因为我无法找到有关 Celery 找不到我的 celeryconfig 文件的信息。芹菜日志中没有任何内容。我在 celeryconfig 中的设置似乎没有生效。我正在使用 Django 1.7.6、Celery 3.1.17,我的项目和应用程序在 virtualenv 中运行。该应用程序由 Apache 和 wsgi 托管。

我正在使用 celeryd 脚本,该脚本链接到 celery 文档中的 github 上。这是我删除了 cmets 的 /etc/default/celery:

CELERYD_NODES="worker1"
CELERY_BIN="/home/celery/.virtualenvs/reporting/bin/celery"
CELERY_APP="main"

CELERYD_CHDIR="/home/celery/dev/reporting"

CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"

CELERYD_USER="celery"
CELERYD_GROUP="celery"
CELERY_CREATE_DIRS=1

CELERY_CONFIG_MODULE="celeryconfig"

如您所见,我已将 CELERYD_CHDIR 设置为我的项目目录(其中包含 manage.py 的目录)。下面我粘贴了 pwd 和 ls 的输出,显示了该目录中的文件:

(reporting)celery@wb-devel:~/dev/reporting$ pwd
/home/celery/dev/reporting
(reporting)celery@wb-devel:~/dev/reporting$ ls
celeryconfig.py  csv_output  manage.py  reports.xml
celeryd          main        reporting  requirements.txt

该文件可供所有人阅读。

这个问题here 建议像这样显式设置 celeryconfig:--settings=celeryconfig 但我不确定在哪里显式设置(在 /etc/init.d/celeryd 中?),我仍然想通过使用 /etc/default/celeryd 中的设置指向 celeryconfig 以正确的方式做事

最后一件事。在我的 celery.py 文件中,我有以下设置:

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'reporting.settings')

app = Celery('main.celery',
          broker='amqp://',
          backend='amqp://',)

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

那么如何让 Celery 找到我的 celeryconfig?可能是因为 celeryconfig 不在我的 python 路径上?我看不出是怎么回事,因为我设置了 CELERYD_CHDIR,而且在我的 apache 配置中,我设置了 python-path:WSGIDaemonProcess web-reports python-path=/home/celery/dev/reporting:/home/celery/.virtualenvs/reporting/lib/python2.7/site-packages

感谢您的帮助

【问题讨论】:

    标签: python django celery


    【解决方案1】:

    我认为问题可能是您混淆了独立与基于 Django 的 celery 的配置。

    一般来说,当你使用 celery 作为一个独立的 Python 项目时,你会创建一个 celeryconfig.py 模块。这显示在First Steps with Celery 中,关键行是:app.config_from_object('celeryconfig')

    但是,当与 Django 集成时,您通常将配置值直接放在标准 Django settings.py 模块中。此变体显示在 First steps with Django 中,关键行更改为:app.config_from_object('django.conf:settings')

    由于您告诉 celery 从 Django 设置模块加载配置,也许您只需将值移动到该文件。

    【讨论】:

      猜你喜欢
      • 2020-06-29
      • 2016-04-18
      • 2021-09-23
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 2012-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多