【发布时间】:2015-06-13 20:06:14
【问题描述】:
当 celery 通过主管运行时,我在某些 Celery 任务中读取环境变量时遇到问题
在/etc/supervisord.conf ...
...
[program:celery]
...
command = /home/myuser/mydevelopment/git/ers_data_app/env/bin/celery worker -A webapp.celery --loglevel=info
stdout_logfile=/home/webdev/logs/celeryworker.log
stderr_logfile=/home/myuser/logs/celeryworkererr.log
environment=FLASK_CONFIG="testing"
在myapp/myfile.py ...
...
print 'the system config is', os.getenv('FLASK_CONFIG')
dburi = app_config.config[os.getenv('FLASK_CONFIG')].DATABASE_URI
在celeryworker.log ...
the system config is None
在celeryworkererr.log ...
...
File "/home/webdev/mydevelopment/git/ers_data_app/webapp/dbmodels/database.py", line 16, in <module>
dburi = app_config.config[os.getenv('FLASK_CONFIG')].DATABASE_URI
KeyError: None
由于supervisor 不启动shell,以下是不必要的,但为了完整起见。
在/etc/profile.d/my_app.sh
export FLASK_CONFIG='testing'
【问题讨论】:
-
尝试将
os.environ转储到日志文件中——其中可能有一些线索
标签: python environment-variables celery supervisord