fix: stabilize rule config and cross-review backend

This commit is contained in:
wren
2026-05-11 02:03:01 +08:00
parent 900fc2e8a2
commit 32fb2a4812
14 changed files with 444 additions and 46 deletions
+18
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
import asyncio
import mimetypes
import sys
from contextlib import asynccontextmanager
@@ -36,12 +37,29 @@ if _NATIVE_LEAUDIT_SRC.exists() and str(_NATIVE_LEAUDIT_SRC) not in sys.path:
def create_app() -> FastAPI:
"""创建并配置 FastAPI 应用。"""
async def _warm_rule_config_summary_cache() -> None:
import logging
logger = logging.getLogger("APP")
try:
from fastapi_modules.fastapi_leaudit.services.impl.ruleConfigServiceImpl import GetRuleConfigServiceSingleton
logger.info("start warming rule-config summary cache")
await GetRuleConfigServiceSingleton().WarmPackSummaries(force=True)
logger.info("rule-config summary cache warmed")
except Exception as exc:
logger.warning("rule-config summary cache warm failed: %s", exc)
@asynccontextmanager
async def lifespan(app: FastAPI):
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("APP").info(f"{APP_NAME} starting...")
warm_task = asyncio.create_task(_warm_rule_config_summary_cache())
app.state.rule_config_warm_task = warm_task
yield
if not warm_task.done():
warm_task.cancel()
logging.getLogger("APP").info(f"{APP_NAME} shutting down...")
app = FastAPI(