refactor: permutate implementation to assert no functional change in preparation (#28160)

This commit is contained in:
David Arnold 2024-10-18 02:40:06 +02:00 committed by GitHub
parent 2f9fd308e8
commit 7a9748a417
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 12 deletions

View file

@ -507,19 +507,20 @@ def get_redis_conn(username=None, password=None):
if not hasattr(frappe.local, "conf"):
raise Exception("You need to call frappe.init")
elif not frappe.local.conf.redis_queue:
conf = frappe.get_site_config()
if not conf.redis_queue:
raise Exception("redis_queue missing in common_site_config.json")
global _redis_queue_conn
cred = frappe._dict()
if frappe.conf.get("use_rq_auth"):
if conf.get("use_rq_auth"):
if username:
cred["username"] = username
cred["password"] = password
else:
cred["username"] = frappe.get_site_config().rq_username or get_bench_id()
cred["password"] = frappe.get_site_config().rq_password
cred["username"] = conf.rq_username or get_bench_id()
cred["password"] = conf.rq_password
elif os.environ.get("RQ_ADMIN_PASWORD"):
cred["username"] = "default"

View file

@ -17,21 +17,22 @@ class RedisQueue:
@classmethod
def get_connection(cls, username=None, password=None):
if frappe.conf.redis_queue_sentinel_enabled:
conf = frappe.get_site_config()
if conf.redis_queue_sentinel_enabled:
from frappe.utils.redis_wrapper import get_sentinel_connection
sentinels = [tuple(node.split(":")) for node in frappe.conf.get("redis_queue_sentinels", [])]
sentinels = [tuple(node.split(":")) for node in conf.get("redis_queue_sentinels", [])]
sentinel = get_sentinel_connection(
sentinels=sentinels,
sentinel_username=frappe.conf.get("redis_queue_sentinel_username"),
sentinel_password=frappe.conf.get("redis_queue_sentinel_password"),
master_username=frappe.conf.get("redis_queue_master_username", username),
master_password=frappe.conf.get("redis_queue_master_password", password),
sentinel_username=conf.get("redis_queue_sentinel_username"),
sentinel_password=conf.get("redis_queue_sentinel_password"),
master_username=conf.get("redis_queue_master_username", username),
master_password=conf.get("redis_queue_master_password", password),
)
conn = sentinel.master_for(frappe.conf.get("redis_queue_master_service"))
conn = sentinel.master_for(conf.get("redis_queue_master_service"))
conn.ping()
return conn
conn = redis.from_url(frappe.conf.redis_queue, username=username, password=password)
conn = redis.from_url(conf.redis_queue, username=username, password=password)
conn.ping()
return conn