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
|
@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.
|
Determines whether the client should retry the connection attempt.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NoReconnect(ReconnectionPolicy):
|
class NoReconnect(ReconnectionPolicy):
|
||||||
def should_retry(self, attempts: int) -> bool:
|
def should_retry(self, attempts: int) -> float | None:
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
|
||||||
class FixedReconnect(ReconnectionPolicy):
|
class FixedReconnect(ReconnectionPolicy):
|
||||||
|
@ -29,8 +28,8 @@ class FixedReconnect(ReconnectionPolicy):
|
||||||
self.max_attempts = attempts
|
self.max_attempts = attempts
|
||||||
self.delay = delay
|
self.delay = delay
|
||||||
|
|
||||||
def should_retry(self, attempts: int) -> bool | float:
|
def should_retry(self, attempts: int) -> float | None:
|
||||||
if attempts < self.max_attempts:
|
if attempts < self.max_attempts:
|
||||||
return self.delay
|
return self.delay
|
||||||
|
|
||||||
return False
|
return None
|
||||||
|
|
|
@ -310,10 +310,8 @@ class Sender:
|
||||||
|
|
||||||
delay = self._reconnection_policy.should_retry(attempts)
|
delay = self._reconnection_policy.should_retry(attempts)
|
||||||
|
|
||||||
if delay:
|
if delay is not None:
|
||||||
if delay is not True:
|
await asyncio.sleep(delay)
|
||||||
await asyncio.sleep(delay)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
self._logger.error(
|
self._logger.error(
|
||||||
f"auto-reconnect failed {attempts} time(s); giving up"
|
f"auto-reconnect failed {attempts} time(s); giving up"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user