Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ry4nnnn committed Aug 5, 2024
1 parent d5bafbf commit d65994d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions collectors/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
from functools import wraps
import time

from notifications.notifier import send_realtime_notifications


def retry(max_retries=3, delay=2):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
def wrapper(self, *args, **kwargs):
retries = 0
while retries < max_retries:
try:
return func(*args, **kwargs)
return func(self, *args, **kwargs)
except requests.RequestException as e:
print(f"Request failed: {e}. Retrying {retries + 1}/{max_retries}...")
retries += 1
time.sleep(delay)
print("Max retries reached. Exiting.")
raise SystemExit("Max retries reached. Exiting.")
msg = f"fail to fetch {self.source_name} data due to network error"
send_realtime_notifications(msg)
return None

return wrapper

Expand Down

0 comments on commit d65994d

Please sign in to comment.