我正试图使用姜戈-rq在django服务器上执行一些异步处理。在遵循文档之后,我将我的环境设置为:
DJANGO_SETTINGS_MODULE=config.settings rqworker high default low 但是在部署之后,我得到了Heroku的错误信息:
ImportError: Could not import settings 'config.settings rqworker high default low' (Is it on sys.path? Is there an import error in the settings file?): No module named settings rqworker high default low知道如何正确引用Django设置变量吗?目前,没有这个配置,一切都在本地工作。
档案结构:
ncla/
api/
views.py <-- using django_rq
config/
setttings.py
ProcFile
run-worker.py
requirements.txtProcfile:
web: gunicorn --pythonpath="$PWD/ncla" config.wsgi:application
worker: python -u run-worker.pyrun-worker.py.run:
import os
import urlparse
from redis import Redis
from rq import Worker, Queue, Connection
listen = ['high', 'default', 'low']
redis_url = os.getenv('REDISTOGO_URL')
if not redis_url:
raise RuntimeError('Set up Redis To Go first.')
urlparse.uses_netloc.append('redis')
url = urlparse.urlparse(redis_url)
conn = Redis(host=url.hostname, port=url.port, db=0, password=url.password)
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()Heroku原木:
2014-05-21T16:52:56.909996+00:00 heroku[router]: at=info method=GET path=/admin/ host=ncla-dev.herokuapp.com request_id=3bc938ba-8550-4d41-9d4a-40d46e9a1aa6 fwd="74.113.160.196" dyno=web.1 connect=2ms service=16ms status=500 bytes=238
2014-05-21T16:52:58.541487+00:00 heroku[router]: at=info method=GET path=/admin/ host=ncla-dev.herokuapp.com request_id=30a9d659-3826-402c-ac30-db2a67d21374 fwd="74.113.160.196" dyno=web.1 connect=5ms service=16ms status=500 bytes=238
2014-05-21T16:52:58.537244+00:00 app[web.1]: 2014-05-21 16:52:58 [7] [ERROR] Error handling request
2014-05-21T16:52:58.537253+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2014-05-21T16:52:58.537256+00:00 app[web.1]: self.load_middleware()
2014-05-21T16:52:58.537264+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
2014-05-21T16:52:58.537249+00:00 app[web.1]: Traceback (most recent call last):
2014-05-21T16:52:58.537252+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 131, in handle_request
2014-05-21T16:52:58.537255+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
2014-05-21T16:52:58.537258+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 46, in load_middleware
2014-05-21T16:52:58.537260+00:00 app[web.1]: for middleware_path in settings.MIDDLEWARE_CLASSES:
2014-05-21T16:52:58.537261+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
2014-05-21T16:52:58.537263+00:00 app[web.1]: self._setup(name)
2014-05-21T16:52:58.537266+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2014-05-21T16:52:58.537267+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
2014-05-21T16:52:58.537269+00:00 app[web.1]: % (self.SETTINGS_MODULE, e)
2014-05-21T16:52:58.537271+00:00 app[web.1]: ImportError: Could not import settings 'config.settings rqworker high default low' (Is it on sys.path? Is there an import error in the settings file?): No module named settings rqworker high default low发布于 2014-05-21 19:03:43
我没有使用上面列出的方法,而是使用以下步骤成功地部署到heroku:
使用以下方法将django-rq添加到requirements.txt文件中:
pip freeze > requirements.txt将Procfile更新为:
web: gunicorn --pythonpath="$PWD/your_app_name" config.wsgi:application
worker: python your_app_name/manage.py rqworker high default low提交并重新部署。然后将新员工添加以下内容:
heroku scale worker=1对于后代,我也用这些信息更新了github上的django-rq ReadMe。
https://stackoverflow.com/questions/23789623
复制相似问题