Minor ExponentialBackoff exp -> steps;
No connection stemps greater than 1 detection
This commit is contained in:
1 parent
024ad975b9
commit
147639a454
2 files changed
+12
-7
No files matched your search
@@ -923,7 +923,8 @@ class Twitch:
|
|||||||
kwargs["proxy"] = self.settings.proxy
|
kwargs["proxy"] = self.settings.proxy
|
||||||
logger.debug(f"Request: ({method=}, {url=}, {kwargs=})")
|
logger.debug(f"Request: ({method=}, {url=}, {kwargs=})")
|
||||||
session_timeout = timedelta(seconds=session.timeout.total or 0)
|
session_timeout = timedelta(seconds=session.timeout.total or 0)
|
||||||
for delay in ExponentialBackoff(maximum=3*60):
|
backoff = ExponentialBackoff(maximum=3*60)
|
||||||
|
for delay in backoff:
|
||||||
if self.gui.close_requested:
|
if self.gui.close_requested:
|
||||||
raise ExitRequest()
|
raise ExitRequest()
|
||||||
elif (
|
elif (
|
||||||
@@ -947,7 +948,7 @@ class Twitch:
|
|||||||
self.print(_("error", "site_down").format(seconds=round(delay)))
|
self.print(_("error", "site_down").format(seconds=round(delay)))
|
||||||
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
||||||
# just so that quick retries that often happen, aren't shown
|
# just so that quick retries that often happen, aren't shown
|
||||||
if delay > 1:
|
if backoff.steps > 1:
|
||||||
self.print(_("error", "no_connection").format(seconds=round(delay)))
|
self.print(_("error", "no_connection").format(seconds=round(delay)))
|
||||||
finally:
|
finally:
|
||||||
if response is not None:
|
if response is not None:
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ class ExponentialBackoff:
|
|||||||
maximum: float = 300,
|
maximum: float = 300,
|
||||||
):
|
):
|
||||||
if base <= 1:
|
if base <= 1:
|
||||||
raise ValueError("base has to be greater than 1")
|
raise ValueError("Base has to be greater than 1")
|
||||||
self.exp: int = 0
|
self.steps: int = 0
|
||||||
self.base: float = float(base)
|
self.base: float = float(base)
|
||||||
self.shift: float = float(shift)
|
self.shift: float = float(shift)
|
||||||
self.maximum: float = float(maximum)
|
self.maximum: float = float(maximum)
|
||||||
@@ -208,12 +208,16 @@ class ExponentialBackoff:
|
|||||||
self.variance_min = 1 - variance
|
self.variance_min = 1 - variance
|
||||||
self.variance_max = 1 + variance
|
self.variance_max = 1 + variance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def exp(self) -> int:
|
||||||
|
return max(0, self.steps - 1)
|
||||||
|
|
||||||
def __iter__(self) -> abc.Iterator[float]:
|
def __iter__(self) -> abc.Iterator[float]:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __next__(self) -> float:
|
def __next__(self) -> float:
|
||||||
value: float = (
|
value: float = (
|
||||||
pow(self.base, self.exp)
|
pow(self.base, self.steps)
|
||||||
* random.uniform(self.variance_min, self.variance_max)
|
* random.uniform(self.variance_min, self.variance_max)
|
||||||
+ self.shift
|
+ self.shift
|
||||||
)
|
)
|
||||||
@@ -222,11 +226,11 @@ class ExponentialBackoff:
|
|||||||
# NOTE: variance can cause the returned value to be lower than the previous one already,
|
# NOTE: variance can cause the returned value to be lower than the previous one already,
|
||||||
# so this should be safe to move past the first return,
|
# so this should be safe to move past the first return,
|
||||||
# to prevent the exponent from getting very big after reaching max and many iterations
|
# to prevent the exponent from getting very big after reaching max and many iterations
|
||||||
self.exp += 1
|
self.steps += 1
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def reset(self) -> None:
|
def reset(self) -> None:
|
||||||
self.exp = 0
|
self.steps = 0
|
||||||
|
|
||||||
|
|
||||||
class OrderedSet(MutableSet[_T]):
|
class OrderedSet(MutableSet[_T]):
|
||||||
|
|||||||
Reference in new issue
Block a user