diff --git a/jobs.py b/jobs.py index 3292ba8..da5f19d 100644 --- a/jobs.py +++ b/jobs.py @@ -3,11 +3,11 @@ import re import time from datetime import datetime, timezone -from functools import wraps import requests import schedule from dotenv import load_dotenv +from tenacity import before_sleep_log, retry, stop_after_attempt, wait_fixed from config import load_config from constants import PRIORITY_TO_SCORE @@ -93,23 +93,14 @@ def with_retries(func): exception and waits RETRY_SLEEP_SECONDS before retrying. After the final attempt, the last exception is re-raised. """ - @wraps(func) - def wrapper(*args, **kwargs): - for attempt in range(MAX_RETRY_COUNT): - try: - return func(*args, **kwargs) - except Exception as e: - logging.error( - "Function %s failed with exception %s", - func.__name__, - type(e).__name__, - exc_info=True, - ) - if attempt == MAX_RETRY_COUNT - 1: - raise - time.sleep(RETRY_SLEEP_SECONDS) - - return wrapper + logger = logging.getLogger(__name__) + retry_decorator = retry( + reraise=True, + stop=stop_after_attempt(MAX_RETRY_COUNT), + wait=wait_fixed(RETRY_SLEEP_SECONDS), + before_sleep=before_sleep_log(logger, logging.ERROR), + ) + return retry_decorator(func) def get_team_members(team_slug: str): diff --git a/requirements.txt b/requirements.txt index d6d99e9..f3e248d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ aiohttp==3.12.14 aiosignal==1.4.0 anyio==4.8.0 attrs==25.1.0 -backoff==2.2.1 black==25.1.0 blinker==1.9.0 botocore==1.36.12 @@ -41,6 +40,7 @@ requests-toolbelt==1.0.0 schedule==1.2.2 six==1.17.0 sniffio==1.3.1 +tenacity==8.2.3 typing_extensions==4.12.2 urllib3==2.6.0 websockets==11.0.3