【发布时间】:2014-05-21 17:03:29
【问题描述】:
我正在尝试使用django-rq 在我的 django 服务器上进行一些异步处理。在关注docs 之后,我将环境设置为:
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.txt
过程文件:
web: gunicorn --pythonpath="$PWD/ncla" config.wsgi:application
worker: python -u run-worker.py
运行-worker.py:
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
【问题讨论】:
-
如果您发布您的文件夹结构可能会对我们有所帮助,以便我们知道配置相对于重要文件的位置。
-
@stormlifter 确定。
-
@stormlifter 已更新。