fix: faster sac-api restart (TimeoutStopSec, SSE cancel on shutdown)
This commit is contained in:
@@ -53,6 +53,7 @@ def _dashboard_snapshot(db: Session) -> dict:
|
||||
|
||||
|
||||
async def _sse_generator():
|
||||
try:
|
||||
while True:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
@@ -61,6 +62,8 @@ async def _sse_generator():
|
||||
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:
|
||||
|
||||
@@ -13,9 +13,11 @@ WorkingDirectory=/opt/security-alert-center/backend
|
||||
# Конфиг читает само приложение (pydantic), не systemd — иначе ломаются пароли с #, $ и т.д.
|
||||
Environment=SAC_CONFIG_FILE=/opt/security-alert-center/config/sac-api.env
|
||||
Environment=PYTHONPATH=/opt/security-alert-center/backend
|
||||
ExecStart=/opt/security-alert-center/backend/.venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 8000
|
||||
ExecStart=/opt/security-alert-center/backend/.venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 8000 --timeout-graceful-shutdown 10
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutStopSec=20
|
||||
TimeoutStartSec=30
|
||||
NoNewPrivileges=true
|
||||
|
||||
[Install]
|
||||
|
||||
Reference in New Issue
Block a user