Skip to content

Commit a223df4

Browse files
authored
[AAP-30722] add Redis cluster-related retry and timeout settings (#1052)
1 parent ea28520 commit a223df4

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/aap_eda/settings/default.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ def _get_secret_key() -> str:
136136
SECRET_KEY = _get_secret_key()
137137

138138

139-
def _get_debug() -> bool:
140-
debug = settings.get("DEBUG", False)
141-
if isinstance(debug, str):
142-
debug = str_to_bool(debug)
143-
if not isinstance(debug, bool):
144-
raise ImproperlyConfigured("DEBUG setting must be a boolean value.")
145-
return debug
139+
def _get_boolean(name: str, default=False) -> bool:
140+
value = settings.get(name, default)
141+
if isinstance(value, str):
142+
value = str_to_bool(value)
143+
if not isinstance(value, bool):
144+
raise ImproperlyConfigured("{name} setting must be a boolean value.")
145+
return value
146146

147147

148-
DEBUG = _get_debug()
148+
DEBUG = _get_boolean("DEBUG")
149149

150150
ALLOWED_HOSTS = settings.get("ALLOWED_HOSTS", [])
151151
ALLOWED_HOSTS = (
@@ -448,7 +448,14 @@ def rq_redis_client_instantiation_parameters():
448448
if REDIS_HA_CLUSTER_HOSTS:
449449
params["mode"] = "cluster"
450450
params["redis_hosts"] = REDIS_HA_CLUSTER_HOSTS
451-
451+
params["socket_keepalive"] = _get_boolean("MQ_SOCKET_KEEP_ALIVE", True)
452+
params["socket_connect_timeout"] = settings.get(
453+
"MQ_SOCKET_CONNECT_TIMEOUT", 10
454+
)
455+
params["socket_timeout"] = settings.get("MQ_SOCKET_TIMEOUT", 10)
456+
params["cluster_error_retry_attempts"] = settings.get(
457+
"MQ_CLUSTER_ERROR_RETRY_ATTEMPTS", 3
458+
)
452459
return params
453460

454461

tests/unit/test_settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
DEFAULT_RULEBOOK_QUEUE_TIMEOUT,
2222
ImproperlyConfigured,
2323
RulebookProcessLogLevel,
24-
_get_debug,
24+
_get_boolean,
2525
get_rq_queues,
2626
get_rulebook_process_log_level,
2727
)
@@ -159,14 +159,14 @@ def test_rq_queues_custom_host_multiple_queues():
159159
],
160160
)
161161
@patch("aap_eda.settings.default.settings")
162-
def test_get_debug(mock_settings, value, expected):
162+
def test_get_boolean(mock_settings, value, expected):
163163
mock_settings.get.return_value = value
164-
result = _get_debug()
164+
result = _get_boolean("DEBUG")
165165
assert result == expected
166166

167167

168168
@patch("aap_eda.settings.default.settings")
169-
def test_get_debug_exception(mock_settings):
169+
def test_get_boolean_exception(mock_settings):
170170
mock_settings.get.return_value = ["something", "else"]
171171
with pytest.raises(ImproperlyConfigured):
172-
_get_debug()
172+
_get_boolean("DEBUG")

0 commit comments

Comments
 (0)