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
This commit is contained in:
parent
5a34e6f3ed
commit
df0cd8b40e
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@ -17,13 +18,16 @@ class Database:
|
|||||||
|
|
||||||
success = False
|
success = False
|
||||||
tries = 0
|
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:
|
try:
|
||||||
return await self._external_call(url)
|
return await self._external_call(url)
|
||||||
except TokenHttpException:
|
except TokenHttpException:
|
||||||
tries += 1
|
tries += 1
|
||||||
return {}
|
raise TokenHttpException
|
||||||
|
|
||||||
async def _external_call(self, url) -> Dict | List:
|
async def _external_call(self, url) -> Dict | List:
|
||||||
async with self.session.get(url) as resp:
|
async with self.session.get(url) as resp:
|
||||||
|
Loading…
Reference in New Issue
Block a user