Python/Django项目中的Heroku / Redis连接错误



我正在尝试设置django,以便它在我的模型中达到某个日期时发送自动电子邮件。然而,我设置了一个Heroku-Redis服务器,并试图连接到它。我创建了一个简单的任务来测试芹菜是否工作,但它总是返回以下错误:

读取套接字时出错:(10054,'已存在的连接被远程主机强制关闭',None, 10054, None)

我根据网站设置芹菜:

celery.py:

import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'incFleet.settings')
app = Celery('incFleet')
# Using a string here means the worker doesn'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 apps.
app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')

Tasks.py

import datetime    
from celery import shared_task, task
from time import sleep
from .models import trucks
from datetime import datetime

@shared_task()
def sleepy(duration):
sleep(duration)
return 0
#@shared_task()
#def send_warning():

我的观点:

def index(request):
sleepy.delay(5)
return render(request, 'Inventory/index.html')

And my settings.py

# Celery Broker - Redis
CELERY_BROKER_URL = 'redis://:p0445df1196b44ba70a9bd0c84545315fec8a5dcbd77c8e8c4bd22ff4cd0a2ff4@ec2-54-167-58-171.compute-1.amazonaws.com:11900/'
CELERY_RESULT_BACKEND = 'redis://:p0445df1196b44ba70a9bd0c84545315fec8a5dcbd77c8e8c4bd22ff4cd0a2ff4@ec2-54-167-58-171.compute-1.amazonaws.com:11900/'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'

过了一会儿,我意识到问题出在办公室的网络上。我试图访问的端口已关闭。当我在实际服务器上激活redis时,它就开始正常工作了。

heroku config | grep REDIS

使用以下代码检查实际的url

相关内容

  • 没有找到相关文章

最新更新