fix(realestate-lab): 매칭 재계산 DB lock 오류 수정

- sqlite3.connect timeout=10 추가 (기본 0초 → 즉시 실패 방지)
- run_matching() 단일 connection으로 통합 (프로필 조회~매칭~저장)
- matches/refresh 엔드포인트 에러 핸들링 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-07 04:51:06 +09:00
parent 535ffea45a
commit 011eac7682
3 changed files with 16 additions and 9 deletions

View File

@@ -2,7 +2,7 @@ import json
import logging
from typing import Dict, Any, List
from .db import get_profile, _conn
from .db import _conn, _profile_row_to_dict
logger = logging.getLogger("realestate-lab")
@@ -115,13 +115,16 @@ def _compute_score(
def run_matching():
"""프로필 기반 매칭을 실행하여 결과를 저장한다."""
profile = get_profile()
if not profile:
logger.info("프로필 미설정 — 매칭 건너뜀")
return
"""프로필 기반 매칭을 실행하여 결과를 저장한다.
단일 connection으로 프로필 조회 + 매칭 + 저장을 처리하여 DB lock 방지.
"""
with _conn() as conn:
profile_row = conn.execute("SELECT * FROM user_profile WHERE id = 1").fetchone()
if not profile_row:
logger.info("프로필 미설정 — 매칭 건너뜀")
return
profile = _profile_row_to_dict(profile_row)
anns = conn.execute(
"SELECT * FROM announcements WHERE status IN ('청약예정', '청약중')"
).fetchall()