diff --git a/app/celery_setup/config.py b/app/celery_setup/config.py index eb99dac..70e9c9b 100644 --- a/app/celery_setup/config.py +++ b/app/celery_setup/config.py @@ -10,12 +10,19 @@ sentinel_url = os.getenv('SENTINEL_HEADLESS_URL') sentinel_transport_opts = json.loads(os.getenv('SENTINEL_TRANSPORT_OPTS', '{}')) redis_url = os.getenv('REDIS_URL') +redis_password = os.getenv('REDIS_PASSWORD') def add_db_num_to_url(url, db_num): return url.replace(f':{redis_port}', f':{redis_port}/{db_num}') +def add_password_to_url(url, password): + if len(password) == 0: + return url + return url.replace('redis://', f'redis://:{password}@') + + if sentinel_url: redisdns = dns.resolver.resolve(sentinel_url, 'A') addressstring = [] @@ -30,5 +37,6 @@ def add_db_num_to_url(url, db_num): result_backend_transport_options = sentinel_transport_opts broker_transport_options = sentinel_transport_opts else: - broker_url = add_db_num_to_url(f"{redis_url}:{redis_port}", broker_db_num) - result_backend = add_db_num_to_url(f"{redis_url}:{redis_port}", result_backend_db_num) + redis_url = add_password_to_url(f"{redis_url}:{redis_port}", redis_password) + broker_url = add_db_num_to_url(redis_url, broker_db_num) + result_backend = add_db_num_to_url(redis_url, result_backend_db_num)