Skip to content

Commit

Permalink
Add retry mechanism to Buff request method(#28)
Browse files Browse the repository at this point in the history
Added a retry mechanism to the Buff class's request method, in the event of a BuffError exception, using the tenacity library. It is set to try a maximum of 5 times, utilizing a random exponential wait strategy with a minimum of 8 seconds and maximum of 60 seconds between attempts, enhancing error tolerance and stability of data fetching operations.

Signed-off-by: hldh214 <hldh214@gmail.com>
  • Loading branch information
hldh214 committed Feb 26, 2024
1 parent 27cbac0 commit ab5aead
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions buff2steam/provider/buff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time

import httpx
import tenacity

from buff2steam import logger
from buff2steam.exceptions import BuffError
Expand Down Expand Up @@ -38,6 +39,11 @@ async def __aenter__(self):
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.opener.aclose()

@tenacity.retry(
wait=tenacity.wait_random_exponential(multiplier=1, min=8, max=60),
stop=tenacity.stop_after_attempt(5),
retry=tenacity.retry_if_exception_type(BuffError)
)
async def request(self, *args, **kwargs) -> dict:
url = kwargs.get('url', args[1])
if url not in self.request_locks:
Expand Down

0 comments on commit ab5aead

Please sign in to comment.