Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 包括Redis在内的Django将继续进行Heroku_Python_Django_Heroku_Redis_Redistogo - Fatal编程技术网

Python 包括Redis在内的Django将继续进行Heroku

Python 包括Redis在内的Django将继续进行Heroku,python,django,heroku,redis,redistogo,Python,Django,Heroku,Redis,Redistogo,在过去的几天里,我一直在尝试为我的网站设置此选项,但一直未能理解此特定错误 我在项目中使用了Django Cookiecutter锅炉夯实机 我使用Redis在本地添加芹菜来执行任务,这很有效 太好了 我已将我的项目部署到Heroku 我现在尝试在我的生产环境中实现相同的任务,但是我现在使用的不是Redis,而是一个名为Redis的heroku插件。我是这样做的 在我的设置中:我从redis to go复制了这个。除了更改urlparse导入以满足Python 3标准外,未进行任何调整 pr

在过去的几天里,我一直在尝试为我的网站设置此选项,但一直未能理解此特定错误

  • 我在项目中使用了Django Cookiecutter锅炉夯实机
  • 我使用Redis在本地添加芹菜来执行任务,这很有效
    太好了
  • 我已将我的项目部署到Heroku
我现在尝试在我的生产环境中实现相同的任务,但是我现在使用的不是Redis,而是一个名为Redis的heroku插件。我是这样做的

在我的设置中:我从redis to go复制了这个。除了更改urlparse导入以满足Python 3标准外,未进行任何调整

production.py
import os

from urllib.parse

import urlparse

redis_url = urlparse(os.environ.get('REDISTOGO_URL', 'redis://localhost:6959'))

CACHES = { 'default': {

'BACKEND': 'redis_cache.RedisCache',

'LOCATION': '%s:%s' % (redis_url.hostname, redis_url.port),

'OPTIONS': {

'DB': 0,

'PASSWORD': redis_url.password, }

}

}
Procfile

我已经在Procfile中添加了以下行,并为我的工作人员添加了第二个dyno

worker: celery -A appname worker --beat
那个工人好像在工作。状态更改,然后关闭。它显然无法连接,请参见错误

Heroku日志

2020-05-16T02:07:58.647226+00:00 app[worker.1]: [2020-05-16 04:07:58,647: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
我做错了什么

我的芹菜配置:

芹菜.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')

app = Celery('rebanq_pro')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
CELERY_BROKER_URL = os.environ.get("REDISTOGO_URL")
CELERY_RESULT_BACKEND = os.environ.get("REDISTOGO_URL")
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
设置.local.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')

app = Celery('rebanq_pro')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
CELERY_BROKER_URL = os.environ.get("REDISTOGO_URL")
CELERY_RESULT_BACKEND = os.environ.get("REDISTOGO_URL")
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
设置.production.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')

app = Celery('rebanq_pro')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE
CELERY_BROKER_URL = os.environ.get("REDISTOGO_URL")
CELERY_RESULT_BACKEND = os.environ.get("REDISTOGO_URL")
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE

请包括您的芹菜配置。该错误消息表示芹菜正在尝试将AMQP用于代理,而不是redis。使用更多信息更新了我的问题。错误消息中的url是否与
REDISTOGO\u url
匹配?如果没有,是否可能您没有使用正确的设置?这听起来很合乎逻辑。查看我的代码,我发现在芹菜.Py中它指的是“config.settings.local”。。。指的是“芹菜经纪人URL=redis://localhost:6379". 链接此项修复了错误。[2020-05-18 03:12:51591:INFO/MainProcess]celery@325c7732-0025-412e-81a1-6C37DE6E7D准备就绪。看来我的芹菜工人准备好了,但没有收到任何任务。请包括你的芹菜配置。该错误消息表示芹菜正在尝试将AMQP用于代理,而不是redis。使用更多信息更新了我的问题。错误消息中的url是否与
REDISTOGO\u url
匹配?如果没有,是否可能您没有使用正确的设置?这听起来很合乎逻辑。查看我的代码,我发现在芹菜.Py中它指的是“config.settings.local”。。。指的是“芹菜经纪人URL=redis://localhost:6379". 链接此项修复了错误。[2020-05-18 03:12:51591:INFO/MainProcess]celery@325c7732-0025-412e-81a1-6C37DE6E7D准备就绪。看来我的芹菜工人准备好了,但没有接到任何任务。