From df0cd8b40e99aabd8d0fff12502e8aec2b1fa577 Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Sun, 8 Dec 2024 18:22:28 -0800 Subject: [PATCH] Properly scream when token database unreachable This increases the retries before giving up and gives a backoff if it's failed once but if token data is unavailable scream loudly --- token_bot/token_database/database.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/token_bot/token_database/database.py b/token_bot/token_database/database.py index 77b4702..11be071 100644 --- a/token_bot/token_database/database.py +++ b/token_bot/token_database/database.py @@ -1,3 +1,4 @@ +import asyncio from typing import Dict, List import aiohttp @@ -17,13 +18,16 @@ class Database: success = False tries = 0 + backoff = 0.1 - while not success and tries < 3: + while not success and tries <= 5: + if tries > 1: + await asyncio.sleep(backoff * tries) try: return await self._external_call(url) except TokenHttpException: tries += 1 - return {} + raise TokenHttpException async def _external_call(self, url) -> Dict | List: async with self.session.get(url) as resp: