fix 500
Some checks failed
CI and deploy / migration-check (push) Failing after 10s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-04-20 11:11:47 +02:00
parent b8515f30df
commit a07f5d57cb
6 changed files with 94 additions and 27 deletions

View File

@@ -54,6 +54,22 @@ async def lifespan(app: FastAPI):
set_pg_pool(pg_pool)
app.state.pg_pool = pg_pool
# Fail fast if Flyway routines are missing (otherwise heartbeat silently goes stale in FE).
async with pg_pool.acquire() as conn:
fn_ok = await conn.fetchval(
"""
select exists(
select 1
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'ems'
and p.proname = 'fn_update_heartbeat'
)
"""
)
if not fn_ok:
raise RuntimeError("Missing DB routine: ems.fn_update_heartbeat")
app.state.ws_log_handler = WSLogHandler()
app.state.ws_log_handler.setLevel(logging.INFO)
logging.getLogger().addHandler(app.state.ws_log_handler)