Les choses sérieuses commencent
This commit is contained in:
parent
7a9fe18463
commit
c63f62721b
41 changed files with 1270 additions and 0 deletions
34
erminig/system/retry.py
Normal file
34
erminig/system/retry.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import time
|
||||
import requests
|
||||
from erminig.config import Config
|
||||
|
||||
|
||||
def retry_on_failure():
|
||||
def decorator(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
attempt = 1
|
||||
while attempt <= Config.RETRY_MAX_ATTEMPTS + 1:
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except requests.exceptions.RequestException as e:
|
||||
name = getattr(args[0], "name", "Unknown")
|
||||
print(
|
||||
f"[{name}] Erreur réseau tentative {attempt}: {e.__class__.__name__}"
|
||||
)
|
||||
if attempt <= Config.RETRY_MAX_ATTEMPTS:
|
||||
print(
|
||||
f"[{name}] Nouvelle tentative dans {Config.RETRY_DELAY_SECONDS}s..."
|
||||
)
|
||||
time.sleep(Config.RETRY_DELAY_SECONDS)
|
||||
attempt += 1
|
||||
else:
|
||||
print(f"[{name}] Abandon après {attempt} tentatives.")
|
||||
return None
|
||||
except Exception as e:
|
||||
name = getattr(args[0], "name", "Unknown")
|
||||
print(f"[{name}] Erreur inconnue dans {func.__name__}: {e}")
|
||||
return None
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
Loading…
Add table
Add a link
Reference in a new issue