fix: ignore empty env vars so API health check can start
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user