From ab9a8312ce2b745ce81a10a2ecb2f1d1b9492ecd Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sun, 6 Aug 2023 09:32:06 +0200 Subject: [PATCH] Add exp backoff to GQL --- twitch.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/twitch.py b/twitch.py index b54a9ee..a24825a 100644 --- a/twitch.py +++ b/twitch.py @@ -1513,7 +1513,8 @@ class Twitch: self, ops: GQLOperation | list[GQLOperation] ) -> JsonType | list[JsonType]: gql_logger.debug(f"GQL Request: {ops}") - while True: + backoff = ExponentialBackoff(maximum=60) + for delay in backoff: try: auth_state = await self.get_auth() async with self.request( @@ -1552,7 +1553,8 @@ class Twitch: break else: return orig_response - await asyncio.sleep(1) + await asyncio.sleep(delay) + raise MinerException() def _merge_data(self, primary_data: JsonType, secondary_data: JsonType) -> JsonType: merged = {}