Refactor reconnection policy handling to use None for no retry instead of False

This commit is contained in:
Jahongir Qurbonov 2025-09-15 13:02:34 +05:00
parent 6e4ee71c32
commit 5fe17a17e2
No known key found for this signature in database
GPG Key ID: 256976CED13D5F2D
2 changed files with 7 additions and 10 deletions

View File

@ -10,16 +10,15 @@ class ReconnectionPolicy(ABC):
"""
@abstractmethod
def should_retry(self, attempts: int) -> bool | float:
def should_retry(self, attempts: int) -> float | None:
"""
Determines whether the client should retry the connection attempt.
"""
pass
class NoReconnect(ReconnectionPolicy):
def should_retry(self, attempts: int) -> bool:
return False
def should_retry(self, attempts: int) -> float | None:
return None
class FixedReconnect(ReconnectionPolicy):
@ -29,8 +28,8 @@ class FixedReconnect(ReconnectionPolicy):
self.max_attempts = attempts
self.delay = delay
def should_retry(self, attempts: int) -> bool | float:
def should_retry(self, attempts: int) -> float | None:
if attempts < self.max_attempts:
return self.delay
return False
return None

View File

@ -310,10 +310,8 @@ class Sender:
delay = self._reconnection_policy.should_retry(attempts)
if delay:
if delay is not True:
await asyncio.sleep(delay)
continue
if delay is not None:
await asyncio.sleep(delay)
else:
self._logger.error(
f"auto-reconnect failed {attempts} time(s); giving up"