feat: backoffice 사이트 트래픽 통계(방문·봇 크롤링) 추가

This commit is contained in:
skkim committed 2026-10-20 13:51:33 +09:00
1 parent 3854aef320
commit 01dd8e7522
33 files changed
+2253 -57

No files matched your search

+21 -1
View File
@@ -6,7 +6,7 @@ from fastapi import FastAPI
from app.utils.logger import get_logger
from app.utils.nvMapPwScraper import NvMapPwScraper
from config import p2v_settings, ssulbox_settings
from config import p2v_settings, ssulbox_settings, traffic_settings
logger = get_logger("core")
@@ -14,6 +14,10 @@ logger = get_logger("core")
_ssul_stop: asyncio.Event = asyncio.Event()
_ssul_task: asyncio.Task | None = None
#: nginx 접근 로그 수집 루프(TRAFFIC_ACCESS_LOG_PATH 가 있을 때). 워커가 여럿이어도 커서 행 잠금으로 한 회차는 하나만 읽는다
_traffic_stop: asyncio.Event = asyncio.Event()
_traffic_task: asyncio.Task | None = None
@asynccontextmanager
async def lifespan(app: FastAPI):
@@ -54,6 +58,13 @@ async def lifespan(app: FastAPI):
p2v_worker.start()
if traffic_settings.TRAFFIC_ACCESS_LOG_PATH:
from app.traffic.services import ingest_service
global _traffic_stop, _traffic_task
_traffic_stop = asyncio.Event()
_traffic_task = asyncio.create_task(ingest_service.run_forever(_traffic_stop), name="traffic-ingest")
await NvMapPwScraper.initiate_scraper()
except asyncio.TimeoutError:
logger.error("Database initialization timed out")
@@ -80,6 +91,15 @@ async def lifespan(app: FastAPI):
logger.warning(f"[ssulbox] 러너 종료 처리 실패: {e}")
_ssul_task.cancel()
# 접근 로그 수집 중단. 쓰던 회차는 커밋 전이면 롤백되고 다음 기동이 같은 커서 위치부터 다시 읽는다
if _traffic_task is not None:
try:
_traffic_stop.set()
await asyncio.wait_for(_traffic_task, timeout=10)
except Exception as e:
logger.warning(f"[traffic] 수집 루프 종료 처리 실패: {e}")
_traffic_task.cancel()
# P2V 워커 중단. 진행 중이던 잡은 다음 기동의 requeue_running 이 이어서 돌린다
if p2v_settings.P2V_ENABLED:
from app.p2v.utils import blob as p2v_blob