fix: ignore empty env vars so API health check can start

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 09:19:04 +08:00
parent 458cc42dd5
commit 667cee33fa
3 changed files with 27 additions and 4 deletions
+22 -2
View File
@@ -1,16 +1,28 @@
from __future__ import annotations
import logging
from fastapi import APIRouter
from packages.config import get_settings
from packages.db import Repository
router = APIRouter(tags=["health"])
log = logging.getLogger("health")
@router.get("/health")
def health() -> dict:
s = get_settings()
try:
s = get_settings()
except Exception as e: # noqa: BLE001
log.exception("settings load failed: %s", e)
return {
"ok": False,
"service": "market_intel",
"product": "比特骆驼行情采集分析",
"error": f"settings: {e}",
}
repo = Repository(s.db_path)
try:
hb = repo.get_heartbeat()
@@ -29,5 +41,13 @@ def health() -> dict:
"option_quotes": repo.count_option_quotes(),
"index_ticks": repo.count_index_ticks(),
}
except Exception as e: # noqa: BLE001
log.exception("health db failed: %s", e)
return {
"ok": False,
"service": "market_intel",
"product": "比特骆驼行情采集分析",
"error": f"db: {e}",
}
finally:
repo.close()
repo.close()