fix: add retry logic for garmin 429 rate limiting
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: garmin-sync-script
|
||||
namespace: garmin
|
||||
data:
|
||||
sync.py: |
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
from datetime import date, timedelta
|
||||
import psycopg2
|
||||
from garminconnect import Garmin
|
||||
@@ -15,8 +8,22 @@ data:
|
||||
password = os.environ["GARMIN_PASSWORD"]
|
||||
db_url = os.environ["DATABASE_URL"]
|
||||
|
||||
# Retry-Login bei 429
|
||||
client = Garmin(email, password)
|
||||
for attempt in range(5):
|
||||
try:
|
||||
client.login()
|
||||
print(f"Login erfolgreich (Versuch {attempt + 1})")
|
||||
break
|
||||
except Exception as e:
|
||||
if "429" in str(e):
|
||||
wait = 60 * (attempt + 1)
|
||||
print(f"Rate limited (429), warte {wait}s...")
|
||||
time.sleep(wait)
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
raise Exception("Login nach 5 Versuchen fehlgeschlagen")
|
||||
|
||||
today = date.today()
|
||||
start = today - timedelta(days=365 * 3)
|
||||
|
||||
Reference in New Issue
Block a user