我现在是 celery 菜鸟,但正在尝试开始。我正在运行 Django 1.4 + django-celery + celery 3.0.21 和 redis 存储后端。我可以让工作人员和 celerybeat 通过以下方式“手动”运行:
python manage.py celeryworker -E -B --loglevel=INFO -n w1.manual
我想将其移至 init-scripts 中。因此,我安装了 celery 提供的两个初始化脚本。我可以根据需要运行它们,并且脚本工作正常。但是,由脚本启动的工作程序失败。它似乎没有找到我的项目的设置。这是/etc/default/celeryd 中我的配置文件的内容:
# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"
# Where to chdir at start.
CELERYD_CHDIR="/var/www/www_project_com/"
# Extra arguments to celeryd
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"
# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
# Workers should run as an unprivileged user.
CELERYD_USER="www-data"
CELERYD_GROUP="www-data"
# Name of the projects settings module
export DJANGO_SETTINGS_MODULE="settings"
我的设置文件实际上分为本地/生产/等。生产设置位于此处:
/var/www/www_project_com/project/settings/production.py
我尝试将配置文件的最后一行更改为:
export DJANGO_SETTINGS_MODULE="project.settings.production"
但似乎没有什么区别。
我知道初始化脚本正在获取设置文件/etc/default/celery,因为该进程正在使用我自定义的用户和组。
很明显,进程失败了,因为日志显示:
consumer: Cannot connect to amqp://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="583f2d3d2b2c18696a6f766876687669" rel="noreferrer noopener nofollow">[email protected]</a>:5672//: [Errno 111] Connection refused.
我认为这是默认设置。我的 Django 项目配置为使用连接字符串使用 Redis:
BROKER_URL = 'redis://localhost:6379/0'
作为解决此问题的另一次尝试,我尝试将最后一行设置为:
export DJANGO_SETTINGS_MODULE="settings.production"
这会导致:
[2013-07-19 05:31:48,117: ERROR/MainProcess] Unrecoverable error: ImportError('No module named settings',)
在日志中。
我做错了什么?
最佳答案
如果您想使用 DJANGO_SETTINGS_MODULE 配置,请确保未设置 CELERY_CONFIG_MODULE 配置。
关于django - Celeryd 似乎找不到我的 Django 项目的设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17746222/