在heroku上使用Django应用程序设置Redistogo

时间:2018-02-12 06:18:06

标签: python django heroku

我是Redistogo的新手:

我已经建立了100%与Heroku合作的项目。

我希望在用户输入后对Django Models(数据库事务)运行一些操作。

执行这些操作需要一些时间,因此我决定通过消息代理,消息队列运行它。

我的第一个偏好是使用Celery,但我无法在Heroku上安装Celery。它没有将“Celery-server”确定为我的要求之一,并且推送失败了。

作为替补,我开始使用RedisToGo,它可以作为Heroku的附加功能。

我能够启动工作人员甚至消息正在排队到Redistogo,但是这些工作被移到了Failed队列中。请在下面找到跟踪日志。

2018-02-12T06:02:19.675113+00:00 app[worker.1]: Traceback (most recent call last):
2018-02-12T06:02:19.675115+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/rq/worker.py", line 789, in perform_job
2018-02-12T06:02:19.675116+00:00 app[worker.1]:     rv = job.perform()
2018-02-12T06:02:19.675118+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/rq/job.py", line 573, in perform
2018-02-12T06:02:19.675119+00:00 app[worker.1]:     self._result = self._execute()
2018-02-12T06:02:19.675121+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/rq/job.py", line 579, in _execute
2018-02-12T06:02:19.675123+00:00 app[worker.1]:     return self.func(*self.args, **self.kwargs)
2018-02-12T06:02:19.675124+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/rq/job.py", line 206, in func
2018-02-12T06:02:19.675126+00:00 app[worker.1]:     return import_attribute(self.func_name)
2018-02-12T06:02:19.675128+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/rq/utils.py", line 152, in import_attribute
2018-02-12T06:02:19.675130+00:00 app[worker.1]:     module = importlib.import_module(module_name)
2018-02-12T06:02:19.675131+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2018-02-12T06:02:19.675133+00:00 app[worker.1]:     return _bootstrap._gcd_import(name[level:], package, level)
2018-02-12T06:02:19.675144+00:00 app[worker.1]:   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2018-02-12T06:02:19.675146+00:00 app[worker.1]:   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2018-02-12T06:02:19.675147+00:00 app[worker.1]:   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2018-02-12T06:02:19.675149+00:00 app[worker.1]:   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2018-02-12T06:02:19.675150+00:00 app[worker.1]:   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2018-02-12T06:02:19.675152+00:00 app[worker.1]:   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2018-02-12T06:02:19.675154+00:00 app[worker.1]:   File "/app/loginapp/views.py", line 4, in <module>
2018-02-12T06:02:19.675155+00:00 app[worker.1]:     from loginapp.forms import studentmaster, UserForm,studmstform,markattdform,User,firstlastpunch,batchmstform
2018-02-12T06:02:19.675157+00:00 app[worker.1]:   File "/app/loginapp/forms.py", line 2, in <module>
2018-02-12T06:02:19.675164+00:00 app[worker.1]:     from django.contrib.auth.models import User
2018-02-12T06:02:19.675166+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 4, in <module>
2018-02-12T06:02:19.675167+00:00 app[worker.1]:     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
2018-02-12T06:02:19.675169+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
2018-02-12T06:02:19.675170+00:00 app[worker.1]:     class AbstractBaseUser(models.Model):
2018-02-12T06:02:19.675172+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 53, in AbstractBaseUser
2018-02-12T06:02:19.675174+00:00 app[worker.1]:     password = models.CharField(_('password'), max_length=128)
2018-02-12T06:02:19.675175+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 1061, in __init__
2018-02-12T06:02:19.675177+00:00 app[worker.1]:     super(CharField, self).__init__(*args, **kwargs)
2018-02-12T06:02:19.675178+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 172, in __init__
2018-02-12T06:02:19.675179+00:00 app[worker.1]:     self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
2018-02-12T06:02:19.675180+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
2018-02-12T06:02:19.675181+00:00 app[worker.1]:     self._setup(name)
2018-02-12T06:02:19.675183+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 39, in _setup
2018-02-12T06:02:19.675184+00:00 app[worker.1]:     % (desc, ENVIRONMENT_VARIABLE))
2018-02-12T06:02:19.675185+00:00 app[worker.1]: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
2018-02-12T06:02:19.675186+00:00 app[worker.1]: 06:02:19 Moving job to 'failed' queue

根据错误,我尝试使用以下命令设置DJANGO_SETTINGS_MODULE

heroku运行DJANGO_SETTINGS_MODULE=django.conf.global_settings

但在此之后,当我尝试在heroku上运行我的应用程序时,heroku应用程序没有启动并开始抛出错误“”SECRET_KEY设置不能为空。“

目前我从heroku删除了配置变量“DJANGO_SETTINGS_MODULE”,该应用正在运行,但没有任何后台工作进程。

另外请建议使用Redis比Celery或任何其他更好,更简单的替代方案更好。

1 个答案:

答案 0 :(得分:0)

按如下方式设置配置变量:

heroku config:set DJANGO_SETTINGS_MODULE=<value> 

为您的整个应用设置config var

使用“heroku run”执行的操作只会影响临时one-off dyno,而不会影响整个应用。