fix: reuse redis connection if not rq auth
This commit is contained in:
parent
3414c0d063
commit
eb17c12dda
1 changed files with 11 additions and 7 deletions
|
|
@ -28,6 +28,9 @@ RQ_JOB_FAILURE_TTL = 7 * 24 * 60 * 60 # 7 days instead of 1 year (default)
|
|||
RQ_RESULTS_TTL = 10 * 60
|
||||
|
||||
|
||||
_redis_queue_conn = None
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_queues_timeout():
|
||||
common_site_config = frappe.get_conf()
|
||||
|
|
@ -47,9 +50,6 @@ def get_queues_timeout():
|
|||
}
|
||||
|
||||
|
||||
redis_connection = None
|
||||
|
||||
|
||||
def enqueue(
|
||||
method: str | Callable,
|
||||
queue: str = "default",
|
||||
|
|
@ -360,7 +360,7 @@ def get_redis_conn(username=None, password=None):
|
|||
elif not frappe.local.conf.redis_queue:
|
||||
raise Exception("redis_queue missing in common_site_config.json")
|
||||
|
||||
global redis_connection
|
||||
global _redis_queue_conn
|
||||
|
||||
cred = frappe._dict()
|
||||
if frappe.conf.get("use_rq_auth"):
|
||||
|
|
@ -374,8 +374,14 @@ def get_redis_conn(username=None, password=None):
|
|||
elif os.environ.get("RQ_ADMIN_PASWORD"):
|
||||
cred["username"] = "default"
|
||||
cred["password"] = os.environ.get("RQ_ADMIN_PASWORD")
|
||||
|
||||
try:
|
||||
redis_connection = RedisQueue.get_connection(**cred)
|
||||
if not cred:
|
||||
if not _redis_queue_conn:
|
||||
_redis_queue_conn = RedisQueue.get_connection()
|
||||
return _redis_queue_conn
|
||||
else:
|
||||
return RedisQueue.get_connection(**cred)
|
||||
except (redis.exceptions.AuthenticationError, redis.exceptions.ResponseError):
|
||||
log(
|
||||
f'Wrong credentials used for {cred.username or "default user"}. '
|
||||
|
|
@ -387,8 +393,6 @@ def get_redis_conn(username=None, password=None):
|
|||
log(f"Please make sure that Redis Queue runs @ {frappe.get_conf().redis_queue}", colour="red")
|
||||
raise
|
||||
|
||||
return redis_connection
|
||||
|
||||
|
||||
def get_queues() -> list[Queue]:
|
||||
"""Get all the queues linked to the current bench."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue