Skip to content

Commit 21af078

Browse files
committed
Merge branch 'master' into library_updates_q2_2023
2 parents d434842 + a8c5029 commit 21af078

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

common/helpers/queue.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
import redis
33
import threading
44
from rq import Queue
5+
from ssl import CERT_NONE
56
from typing import Callable
67
from django.conf import settings
8+
from urllib.parse import urlparse
79

8-
redis_url = os.getenv('REDIS_URL', 'redis://localhost:6379')
9-
conn = redis.from_url(redis_url)
10-
q = settings.REDIS_ENABLED and Queue(connection=conn)
1110

11+
redis_url = os.getenv('REDIS_URL','redis://localhost:6379')
12+
url = urlparse(redis_url)
13+
# Check if the Redis connection is using SSL/TSL
14+
is_secure = redis_url.startswith('rediss://')
15+
16+
if is_secure:
17+
conn = redis.Redis(host=url.hostname, port=url.port, username=url.username, password=url.password, ssl=True, ssl_cert_reqs=None)
18+
else:
19+
conn = redis.from_url(redis_url)
20+
21+
q = settings.REDIS_ENABLED and Queue(connection=conn)
1222

1323
def enqueue(job_func: Callable, *args):
1424
if settings.REDIS_ENABLED:
@@ -21,3 +31,4 @@ def enqueue(job_func: Callable, *args):
2131
thread = threading.Thread(target=job_func, args=args)
2232
thread.daemon = True
2333
thread.start()
34+

0 commit comments

Comments
 (0)