Skip to content

Commit c75bb2c

Browse files
committed
sonar
1 parent 61ff8ff commit c75bb2c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/service-library/src/servicelib/redis/_semaphore.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
stop_never,
2323
wait_random_exponential,
2424
)
25+
from tenacity.stop import stop_base
2526

2627
from ._client import RedisClientSDK
2728
from ._constants import (
@@ -206,18 +207,19 @@ async def acquire(self) -> bool:
206207

207208
ttl_seconds = int(self.ttl.total_seconds())
208209

210+
# Determine retry stop condition based on blocking configuration
211+
stop_condition: stop_base = stop_after_delay(0)
212+
if self.blocking:
213+
stop_condition = (
214+
stop_after_delay(self.blocking_timeout)
215+
if self.blocking_timeout
216+
else stop_never
217+
)
218+
209219
try:
210220

211221
@retry(
212-
stop=(
213-
stop_after_delay(0)
214-
if not self.blocking
215-
else (
216-
stop_after_delay(self.blocking_timeout)
217-
if self.blocking_timeout
218-
else stop_never
219-
)
220-
),
222+
stop=stop_condition,
221223
wait=wait_random_exponential(min=0.1, max=0.5),
222224
retry=retry_if_exception_type(redis.exceptions.TimeoutError),
223225
)

0 commit comments

Comments
 (0)