初始化集成qgis
This commit is contained in:
+23
-2
@@ -9,6 +9,7 @@ from fastapi import FastAPI, Request
|
||||
from app.utils.api_deps import get_rainfall_model, get_earthquake_model, is_model_loaded
|
||||
from app.schemas.api_schemas import HealthResponse
|
||||
from app.config.paths import get_logger
|
||||
from config import settings
|
||||
|
||||
logger = get_logger("api")
|
||||
|
||||
@@ -20,9 +21,29 @@ async def lifespan(app: FastAPI):
|
||||
get_rainfall_model()
|
||||
get_earthquake_model()
|
||||
logger.info("DBN模型预加载完成")
|
||||
yield
|
||||
logger.info("应用关闭")
|
||||
|
||||
# 初始化 QGIS 环境
|
||||
qgis_root = getattr(settings, "QGIS_ROOT", None)
|
||||
if qgis_root:
|
||||
try:
|
||||
from app.services.qgis.qgis_env import init_qgis_env
|
||||
init_qgis_env(qgis_root)
|
||||
logger.info("QGIS 环境初始化完成")
|
||||
except Exception as e:
|
||||
logger.error(f"QGIS 环境初始化失败(专题图功能不可用): {e}")
|
||||
|
||||
yield
|
||||
|
||||
# 清理 QGIS 资源
|
||||
try:
|
||||
from app.services.qgis.qgis_env import cleanup_qgis_env
|
||||
from app.services.qgis.map_service import template_cache
|
||||
template_cache.cleanup()
|
||||
cleanup_qgis_env()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
logger.info("应用关闭")
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
"""创建 FastAPI 应用实例"""
|
||||
|
||||
Reference in New Issue
Block a user