fix: stabilize rule config and cross-review backend
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user