build: updated config for redis and wait_for_db command

This commit is contained in:
pablohashescobar 2022-12-13 20:47:49 +05:30
parent db10c884e8
commit 4414a71331
7 changed files with 40 additions and 21 deletions

View file

@ -0,0 +1,19 @@
import time
from django.db import connections
from django.db.utils import OperationalError
from django.core.management import BaseCommand
class Command(BaseCommand):
"""Django command to pause execution until db is available"""
def handle(self, *args, **options):
self.stdout.write('Waiting for database...')
db_conn = None
while not db_conn:
try:
db_conn = connections['default']
except OperationalError:
self.stdout.write('Database unavailable, waititng 1 second...')
time.sleep(1)
self.stdout.write(self.style.SUCCESS('Database available!'))

View file

@ -6,17 +6,7 @@ from urllib.parse import urlparse
def redis_instance():
if settings.REDIS_URL:
tls_url = os.environ.get("REDIS_TLS_URL", False)
url = urlparse(settings.REDIS_URL)
if tls_url:
url = urlparse(tls_url)
ri = redis.Redis(
host=url.hostname,
port=url.port,
password=url.password,
ssl=True,
ssl_cert_reqs=None,
)
ri = redis.from_url(settings.REDIS_URL, db=0)
else:
ri = redis.StrictRedis(host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=0)