【发布时间】: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
感谢您的帮助
【问题讨论】: