fix: faster sac-api restart (TimeoutStopSec, SSE cancel on shutdown)

This commit is contained in:
PTah
2026-05-27 14:53:54 +10:00
parent 61c9f9b673
commit 8995a34037
2 changed files with 14 additions and 9 deletions
+11 -8
View File
@@ -53,14 +53,17 @@ def _dashboard_snapshot(db: Session) -> dict:
async def _sse_generator():
while True:
db = SessionLocal()
try:
payload = _dashboard_snapshot(db)
finally:
db.close()
yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
await asyncio.sleep(SSE_INTERVAL_SEC)
try:
while True:
db = SessionLocal()
try:
payload = _dashboard_snapshot(db)
finally:
db.close()
yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
await asyncio.sleep(SSE_INTERVAL_SEC)
except asyncio.CancelledError:
return
def _sse_auth(token: str = Query(..., description="JWT access_token")) -> str: