This commit is contained in:
2026-07-10 19:01:33 +09:00
parent e3d66e717c
commit b98affbf99
22 changed files with 1681 additions and 752 deletions
+31 -1
View File
@@ -23,6 +23,7 @@ from B05_wf2_Route.B05_wf2_Route_Schema import (
RouteSolveResponse,
)
from common_util.common_util_storage import resolve_stored_project_path
from common_util.common_util_workflow_state import complete_stage, fail_stage, start_stage
from config.config_db import get_db_pool
logger = logging.getLogger(__name__)
@@ -36,7 +37,20 @@ async def solve_route(
"""경로 탐색을 실행하고 결과를 GeoJSON 저장 + DB 기록한다."""
pool = get_db_pool()
try:
params = {
"filter_key": request.filter_key,
"method": request.method,
"smooth": request.smooth,
"points": request.points,
"options": request.options(),
"algorithm": request.algorithm,
"surface_model_id": request.surface_model_id,
}
async with pool.acquire() as connection:
async with connection.cursor() as cursor:
await start_stage(cursor, str(project_id), 2, params)
await connection.commit()
stored_path = await get_project_storage_relative_path(connection, project_id)
project_root = Path(resolve_stored_project_path(stored_path))
@@ -78,6 +92,8 @@ async def solve_route(
mean_slope=stats["mean_slope"],
cost_score=stats["cost_score"],
)
async with connection.cursor() as cursor:
await complete_stage(cursor, str(project_id), 2)
await connection.commit()
except Exception:
await connection.rollback()
@@ -92,13 +108,25 @@ async def solve_route(
route_data_path=design["route_data_path"],
)
except LookupError as exc:
async with pool.acquire() as connection, connection.cursor() as cursor:
await fail_stage(cursor, str(project_id), 2, str(exc))
await connection.commit()
return JSONResponse(status_code=404, content={"status": "error", "message": str(exc)})
except FileNotFoundError as exc:
async with pool.acquire() as connection, connection.cursor() as cursor:
await fail_stage(cursor, str(project_id), 2, str(exc))
await connection.commit()
return JSONResponse(status_code=404, content={"status": "error", "message": str(exc)})
except (OSError, ValueError) as exc:
async with pool.acquire() as connection, connection.cursor() as cursor:
await fail_stage(cursor, str(project_id), 2, str(exc))
await connection.commit()
return JSONResponse(status_code=400, content={"status": "error", "message": str(exc)})
except Exception:
except Exception as exc:
logger.exception("B05 경로 탐색 실패: project_id=%s", project_id)
async with pool.acquire() as connection, connection.cursor() as cursor:
await fail_stage(cursor, str(project_id), 2, str(exc))
await connection.commit()
return JSONResponse(
status_code=500,
content={"status": "error", "message": "경로 탐색 처리 중 오류가 발생했습니다."},
@@ -120,6 +148,8 @@ async def confirm_latest_route(project_id: UUID) -> RouteConfirmResponse | JSONR
await connection.begin()
try:
await confirm_route(connection, latest["id"])
async with connection.cursor() as cursor:
await complete_stage(cursor, str(project_id), 2)
await connection.commit()
except Exception:
await connection.rollback()