添加并发请求限制,避免崩溃
This commit is contained in:
@@ -20,7 +20,6 @@ from app.config.paths import get_logger
|
||||
from app.config.qgis_mappings import build_static_layers_config, get_gpkg_dir
|
||||
from app.repositories import qgis_repository
|
||||
from app.schemas.api_schemas import QgisMapExportResponse, QgisMapExportRequest
|
||||
from app.utils.api_deps import get_prediction_semaphore
|
||||
from app.utils.db_helper import db_helper
|
||||
from config import settings
|
||||
|
||||
@@ -179,18 +178,22 @@ def _build_qgis_config(batch_folder: str) -> dict:
|
||||
# 接口实现
|
||||
# ============================================================
|
||||
|
||||
# 全局并发限制
|
||||
import asyncio as _asyncio
|
||||
_concurrent = getattr(settings, "QGIS_MAX_CONCURRENT", 2)
|
||||
_qgis_semaphore = _asyncio.Semaphore(_concurrent)
|
||||
|
||||
|
||||
@router.post("/export/map", response_model=QgisMapExportResponse, summary="QGIS 批量专题图导出")
|
||||
async def export_map(req: QgisMapExportRequest):
|
||||
"""
|
||||
根据模拟ID批量导出专题图。同一 occurred_time 视为同一场灾害,共享文件夹
|
||||
根据模拟ID批量导出专题图。同一 inferenceId 共享文件夹,增量产出缺失图片。
|
||||
"""
|
||||
from app.services.qgis.qgis_env import is_qgis_available
|
||||
if not is_qgis_available():
|
||||
raise HTTPException(status_code=503, detail="QGIS 环境不可用(未找到 QGIS Python 3.12 解释器)")
|
||||
raise HTTPException(status_code=503, detail="QGIS 环境不可用")
|
||||
|
||||
semaphore = get_prediction_semaphore()
|
||||
|
||||
async with semaphore:
|
||||
async with _qgis_semaphore:
|
||||
inference_id = req.inferenceId
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user