feat: p2v 연동
This commit is contained in:
1 parent
b3385e7df2
commit
5de5c7507d
26 files changed
+2944
-9
No files matched your search
@@ -54,6 +54,28 @@ async def lifespan(app: FastAPI):
|
||||
f"{type(e).__name__}: {e}"
|
||||
)
|
||||
|
||||
# P2V 고아 잡 스윕 — 검수 방치·크래시로 남은 선차감분을 환불하고,
|
||||
# archiving 에 갇힌 잡을 재시도 가능 상태로 되돌린다 (설계 R-1·R-3).
|
||||
# 스키마는 앱이 만들지 않는다 — migration_2026-08-25_p2v.sql 수동 실행.
|
||||
from config import p2v_settings
|
||||
|
||||
if p2v_settings.P2V_ENABLED:
|
||||
try:
|
||||
from app.database.session import BackgroundSessionLocal
|
||||
from app.p2v.services import f1_service, f2_service
|
||||
|
||||
async with BackgroundSessionLocal() as session:
|
||||
swept = await f1_service.sweep_orphans(session)
|
||||
swept += await f2_service.sweep_orphans(session)
|
||||
await session.commit()
|
||||
if swept:
|
||||
logger.info(f"[p2v] 고아 잡 {swept}건 환불·정리")
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"[p2v] 고아 스윕 실패 (다음 기동 시 재시도): "
|
||||
f"{type(e).__name__}: {e}"
|
||||
)
|
||||
|
||||
await NvMapPwScraper.initiate_scraper()
|
||||
except asyncio.TimeoutError:
|
||||
logger.error("Database initialization timed out")
|
||||
@@ -82,9 +104,11 @@ async def lifespan(app: FastAPI):
|
||||
# 공유 HTTP 클라이언트 종료
|
||||
from app.utils.creatomate import close_shared_client
|
||||
from app.utils.upload_blob_as_request import close_shared_blob_client
|
||||
from app.p2v.services.client import close_client as close_p2v_client
|
||||
|
||||
await close_shared_client()
|
||||
await close_shared_blob_client()
|
||||
await close_p2v_client()
|
||||
|
||||
from app.database.like_cache import close_like_cache
|
||||
await close_like_cache()
|
||||
|
||||
@@ -345,6 +345,24 @@ def add_exception_handlers(app: FastAPI):
|
||||
},
|
||||
)
|
||||
|
||||
# P2vException 핸들러 추가
|
||||
# (SsulboxException 과 같은 (message, status_code, code) 형태 — 수동 등록)
|
||||
from app.p2v.exceptions import P2vException
|
||||
|
||||
@app.exception_handler(P2vException)
|
||||
def p2v_exception_handler(request: Request, exc: P2vException) -> Response:
|
||||
if exc.status_code < 500:
|
||||
logger.warning(f"Handled P2vException: {exc.__class__.__name__} - {exc.message}")
|
||||
else:
|
||||
logger.error(f"Handled P2vException: {exc.__class__.__name__} - {exc.message}")
|
||||
return JSONResponse(
|
||||
status_code=exc.status_code,
|
||||
content={
|
||||
"detail": exc.message,
|
||||
"code": exc.code,
|
||||
},
|
||||
)
|
||||
|
||||
@app.exception_handler(status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
def internal_server_error_handler(request, exception):
|
||||
# 에러 메시지 로깅 (한글 포함 가능)
|
||||
|
||||
Reference in new issue
Block a user