fix: faster sac-api restart (TimeoutStopSec, SSE cancel on shutdown)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user