fixed rate limit

This commit is contained in:
nathan 2026-01-14 23:09:40 +00:00
parent 76760bdaaf
commit e4be2cb69c

View file

@ -27,6 +27,9 @@ def rate_limited(func):
"""Decorator to enforce rate limiting on Tidal API calls"""
@wraps(func)
def wrapper(*args, **kwargs):
max_retries = 3
last_exception = None
for attempt in range(max_retries):
global _last_api_call_time
with _api_call_lock:
@ -43,14 +46,18 @@ def rate_limited(func):
result = func(*args, **kwargs)
return result
except Exception as e:
last_exception = e
# Implement exponential backoff for API errors
if "rate limit" in str(e).lower() or "429" in str(e):
logger.warning(f"Rate limit hit, implementing backoff: {e}")
time.sleep(3.0) # Wait 3 seconds before retrying
continue
elif "503" in str(e) or "502" in str(e):
logger.warning(f"Tidal service error, backing off: {e}")
time.sleep(2.0) # Wait 2 seconds for service errors
raise
continue
raise last_exception
return wrapper
@dataclass