Delete utils/retry.py
Browse files- utils/retry.py +0 -32
utils/retry.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
from fastapi import HTTPException
|
| 2 |
-
|
| 3 |
-
from utils.Logger import logger
|
| 4 |
-
from utils.config import retry_times
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
async def async_retry(func, *args, max_retries=retry_times, **kwargs):
|
| 8 |
-
for attempt in range(max_retries + 1):
|
| 9 |
-
try:
|
| 10 |
-
result = await func(*args, **kwargs)
|
| 11 |
-
return result
|
| 12 |
-
except HTTPException as e:
|
| 13 |
-
if attempt == max_retries:
|
| 14 |
-
logger.error(f"Throw an exception {e.status_code}, {e.detail}")
|
| 15 |
-
if e.status_code == 500:
|
| 16 |
-
raise HTTPException(status_code=500, detail="Server error")
|
| 17 |
-
raise HTTPException(status_code=e.status_code, detail=e.detail)
|
| 18 |
-
logger.info(f"Retry {attempt + 1} status code {e.status_code}, {e.detail}. Retrying...")
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
def retry(func, *args, max_retries=retry_times, **kwargs):
|
| 22 |
-
for attempt in range(max_retries + 1):
|
| 23 |
-
try:
|
| 24 |
-
result = func(*args, **kwargs)
|
| 25 |
-
return result
|
| 26 |
-
except HTTPException as e:
|
| 27 |
-
if attempt == max_retries:
|
| 28 |
-
logger.error(f"Throw an exception {e.status_code}, {e.detail}")
|
| 29 |
-
if e.status_code == 500:
|
| 30 |
-
raise HTTPException(status_code=500, detail="Server error")
|
| 31 |
-
raise HTTPException(status_code=e.status_code, detail=e.detail)
|
| 32 |
-
logger.error(f"Retry {attempt + 1} status code {e.status_code}, {e.detail}. Retrying...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|