mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-09-19 02:12:40 +03:00
Refactor reconnection policy handling to use None for no retry instead of False
This commit is contained in:
parent
6e4ee71c32
commit
5fe17a17e2
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user