Skip to content

Commit

Permalink
Fix delays
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Sep 21, 2023
1 parent 5470f98 commit ace25fe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions reportportal_client/aio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import sys
from typing import Coroutine

import aiohttp
from aenum import Enum
from aiohttp import ClientResponse, ServerConnectionError, \
from aiohttp import ClientSession, ClientResponse, ServerConnectionError, \
ClientResponseError

DEFAULT_RETRY_NUMBER: int = 5
DEFAULT_RETRY_DELAY: int = 5
DEFAULT_RETRY_DELAY: float = 0.005
THROTTLING_STATUSES: set = {425, 429}
RETRY_STATUSES: set = {408, 500, 502, 503, 507}.union(THROTTLING_STATUSES)

Expand All @@ -32,15 +31,15 @@ class RetryClass(int, Enum):
THROTTLING = 3


class RetryingClientSession(aiohttp.ClientSession):
class RetryingClientSession(ClientSession):
__retry_number: int
__retry_delay: int
__retry_delay: float

def __init__(
self,
*args,
max_retry_number: int = DEFAULT_RETRY_NUMBER,
base_retry_delay: int = DEFAULT_RETRY_DELAY,
base_retry_delay: float = DEFAULT_RETRY_DELAY,
**kwargs
):
super().__init__(*args, **kwargs)
Expand All @@ -52,7 +51,8 @@ async def __nothing(self):

def __sleep(self, retry_num: int, retry_factor: int) -> Coroutine:
if retry_num > 0: # don't wait at the first retry attempt
return asyncio.sleep((retry_factor * self.__retry_delay) ** retry_num)
delay = (((retry_factor * self.__retry_delay) * 1000) ** retry_num) / 1000
return asyncio.sleep(delay)
else:
return self.__nothing()

Expand Down

0 comments on commit ace25fe

Please sign in to comment.