From 6c9d271ae145cb2f8c8eda610a9af7426fb70546 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Thu, 18 Jan 2024 18:05:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20redis=20=E5=AF=86=E7=A0=81=E6=9C=89?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6celery=20beat=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/start_celery_beat.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils/start_celery_beat.py b/utils/start_celery_beat.py index 19d578e70..2f089a4af 100644 --- a/utils/start_celery_beat.py +++ b/utils/start_celery_beat.py @@ -1,13 +1,12 @@ #!/usr/bin/env python # import os -import sys import signal import subprocess +import sys import redis_lock - -from redis import Redis, Sentinel +from redis import Redis, Sentinel, ConnectionPool BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) APPS_DIR = os.path.join(BASE_DIR, 'apps') @@ -50,9 +49,15 @@ if REDIS_SENTINEL_SERVICE_NAME and REDIS_SENTINELS: ) redis_client = sentinel_client.master_for(REDIS_SENTINEL_SERVICE_NAME) else: - connection_params['host'] = settings.REDIS_HOST - connection_params['port'] = settings.REDIS_PORT - redis_client = Redis(**connection_params) + REDIS_PROTOCOL = 'rediss' if settings.REDIS_USE_SSL else 'redis' + REDIS_LOCATION_NO_DB = '%(protocol)s://:%(password)s@%(host)s:%(port)s' % { + 'protocol': REDIS_PROTOCOL, + 'password': settings.REDIS_PASSWORD, + 'host': settings.REDIS_HOST, + 'port': settings.REDIS_PORT, + } + pool = ConnectionPool.from_url(REDIS_LOCATION_NO_DB, **connection_params) + redis_client = Redis(connection_pool=pool) scheduler = "ops.celery.beat.schedulers:DatabaseScheduler" processes = []