fix 500
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -126,9 +126,9 @@ async def get_site_status_full(
|
||||
tomorrow_slots = int(bundle.get("tomorrow_price_slot_count") or 0)
|
||||
|
||||
now_utc = datetime.now(timezone.utc)
|
||||
hb_last = hb_row.get("last_seen") if hb_row else None
|
||||
hb_last = _parse_ts(hb_row.get("last_seen") if hb_row else None)
|
||||
hb_age = _age_seconds(hb_last)
|
||||
inv_measured = inv_row.get("measured_at") if inv_row else None
|
||||
inv_measured = _parse_ts(inv_row.get("measured_at") if inv_row else None)
|
||||
inv_age = _age_seconds(inv_measured)
|
||||
|
||||
next_start, next_bat = _next_plan_interval(intervals, now_utc)
|
||||
|
||||
Reference in New Issue
Block a user