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():
|
async def _sse_generator():
|
||||||
while True:
|
try:
|
||||||
db = SessionLocal()
|
while True:
|
||||||
try:
|
db = SessionLocal()
|
||||||
payload = _dashboard_snapshot(db)
|
try:
|
||||||
finally:
|
payload = _dashboard_snapshot(db)
|
||||||
db.close()
|
finally:
|
||||||
yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
|
db.close()
|
||||||
await asyncio.sleep(SSE_INTERVAL_SEC)
|
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:
|
def _sse_auth(token: str = Query(..., description="JWT access_token")) -> str:
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ WorkingDirectory=/opt/security-alert-center/backend
|
|||||||
# Конфиг читает само приложение (pydantic), не systemd — иначе ломаются пароли с #, $ и т.д.
|
# Конфиг читает само приложение (pydantic), не systemd — иначе ломаются пароли с #, $ и т.д.
|
||||||
Environment=SAC_CONFIG_FILE=/opt/security-alert-center/config/sac-api.env
|
Environment=SAC_CONFIG_FILE=/opt/security-alert-center/config/sac-api.env
|
||||||
Environment=PYTHONPATH=/opt/security-alert-center/backend
|
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
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
|
TimeoutStopSec=20
|
||||||
|
TimeoutStartSec=30
|
||||||
NoNewPrivileges=true
|
NoNewPrivileges=true
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
Reference in New Issue
Block a user