Fix: EL-Retry bei 429 (Free-Tier-Concurrency) + index.html no-cache (immer frisches Bundle)

5 parallele EL-Calls -> 1x 502 (Concurrency-Limit). elevenlabs_tts retryt jetzt 429/5xx mit Backoff.
index.html wird nicht mehr gecacht -> nach Deploy kein altes Bundle mehr.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hitonabi
2026-06-28 02:02:50 +02:00
parent 6d7a17e765
commit dd4c4c8c0f
2 changed files with 22 additions and 9 deletions
+2 -1
View File
@@ -86,6 +86,7 @@ if FRONTEND_DIST.exists():
index = FRONTEND_DIST / "index.html" index = FRONTEND_DIST / "index.html"
if index.exists(): if index.exists():
return FileResponse(index) # index.html nie cachen → Browser zieht nach jedem Deploy das aktuelle (gehashte) Bundle.
return FileResponse(index, headers={"Cache-Control": "no-cache, must-revalidate"})
return {"detail": "frontend not built"} return {"detail": "frontend not built"}
+15 -3
View File
@@ -233,14 +233,26 @@ def elevenlabs_tts(text: str, voice: str) -> bytes:
data=body, data=body,
headers={"xi-api-key": key, "Content-Type": "application/json", "Accept": "audio/mpeg"}, headers={"xi-api-key": key, "Content-Type": "application/json", "Accept": "audio/mpeg"},
) )
import time
# Free-Tier hat ein Concurrency-Limit → parallele Sätze geben 429. Retry mit Backoff fängt das ab.
last = ""
for attempt in range(4):
try: try:
with urllib.request.urlopen(req, timeout=60) as r: with urllib.request.urlopen(req, timeout=60) as r:
return r.read() return r.read()
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
detail = e.read()[:200].decode("utf-8", "replace") last = f"{e.code}: {e.read()[:200].decode('utf-8', 'replace')}"
raise HTTPException(502, f"ElevenLabs-Fehler {e.code}: {detail}") if e.code in (429, 500, 502, 503, 529) and attempt < 3:
time.sleep(0.5 * (attempt + 1))
continue
raise HTTPException(502, f"ElevenLabs-Fehler {last}")
except urllib.error.URLError as e: except urllib.error.URLError as e:
raise HTTPException(502, f"ElevenLabs nicht erreichbar: {e}") last = str(e)
if attempt < 3:
time.sleep(0.5 * (attempt + 1))
continue
raise HTTPException(502, f"ElevenLabs nicht erreichbar: {last}")
raise HTTPException(502, f"ElevenLabs-Fehler (nach Retries): {last}")
def elevenlabs_list() -> list[dict]: def elevenlabs_list() -> list[dict]: