34 lines
938 B
Python
34 lines
938 B
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from packages.config import get_settings
|
|
from packages.db import Repository
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
|
|
@router.get("/health")
|
|
def health() -> dict:
|
|
s = get_settings()
|
|
repo = Repository(s.db_path)
|
|
try:
|
|
hb = repo.get_heartbeat()
|
|
last_ok = hb.get("last_ok_ts_ms")
|
|
lag_ms = None
|
|
if last_ok:
|
|
import time
|
|
|
|
lag_ms = max(0, int(time.time() * 1000) - int(last_ok))
|
|
return {
|
|
"ok": True,
|
|
"service": "market_intel",
|
|
"product": "比特骆驼行情采集分析",
|
|
"collector_lag_ms": lag_ms,
|
|
"consecutive_failures": hb.get("consecutive_failures", 0),
|
|
"option_quotes": repo.count_option_quotes(),
|
|
"index_ticks": repo.count_index_ticks(),
|
|
}
|
|
finally:
|
|
repo.close()
|