Compare commits
3 Commits
f6de95afb6
...
8411e2c73e
| Author | SHA1 | Date | |
|---|---|---|---|
| 8411e2c73e | |||
| 86a6b75124 | |||
| 08a32e4357 |
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
import logging
|
import logging
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
import requests
|
import requests
|
||||||
@@ -53,17 +54,28 @@ def _api_call(endpoint: str, params: Dict[str, Any] = None) -> List[Dict]:
|
|||||||
all_data: List[Dict] = []
|
all_data: List[Dict] = []
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
|
_MAX_RETRIES = 2
|
||||||
while True:
|
while True:
|
||||||
base_params["page"] = page
|
base_params["page"] = page
|
||||||
|
body = None
|
||||||
|
for attempt in range(_MAX_RETRIES + 1):
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url, params=base_params, timeout=30)
|
resp = requests.get(url, params=base_params, timeout=30)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
body = resp.json()
|
body = resp.json()
|
||||||
except requests.RequestException as e:
|
|
||||||
logger.error("API 호출 실패 [%s page=%d]: %s", endpoint, page, e)
|
|
||||||
break
|
break
|
||||||
|
except requests.RequestException as e:
|
||||||
|
if attempt < _MAX_RETRIES:
|
||||||
|
logger.warning("API 호출 실패 [%s page=%d] — %d초 후 재시도 (%d/%d): %s",
|
||||||
|
endpoint, page, 2 ** attempt, attempt + 1, _MAX_RETRIES, e)
|
||||||
|
time.sleep(2 ** attempt)
|
||||||
|
else:
|
||||||
|
logger.error("API 호출 최종 실패 [%s page=%d]: %s", endpoint, page, e)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
logger.error("JSON 파싱 실패 [%s page=%d]: %s", endpoint, page, e)
|
logger.error("JSON 파싱 실패 [%s page=%d]: %s", endpoint, page, e)
|
||||||
|
break # 파싱 오류는 재시도 무의미
|
||||||
|
|
||||||
|
if body is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
data = body.get("data", [])
|
data = body.get("data", [])
|
||||||
|
|||||||
@@ -86,8 +86,10 @@ def _check_eligible_types(profile: Dict[str, Any], ann: Dict[str, Any]) -> List[
|
|||||||
elif is_homeless:
|
elif is_homeless:
|
||||||
eligible.append("일반2순위")
|
eligible.append("일반2순위")
|
||||||
|
|
||||||
# 특별공급 — 신혼부부 (소득 160% 이하)
|
# 특별공급 — 신혼부부 (소득 160% 이하, 혼인 84개월 이내)
|
||||||
if profile.get("is_newlywed") and is_homeless:
|
marriage_months = profile.get("marriage_months")
|
||||||
|
newlywed_ok = (marriage_months is None) or (marriage_months <= 84)
|
||||||
|
if profile.get("is_newlywed") and is_homeless and newlywed_ok:
|
||||||
if income_pct is None or income_pct <= 160:
|
if income_pct is None or income_pct <= 160:
|
||||||
eligible.append("특별-신혼부부")
|
eligible.append("특별-신혼부부")
|
||||||
|
|
||||||
@@ -203,7 +205,7 @@ def run_matching():
|
|||||||
profile = _profile_row_to_dict(profile_row)
|
profile = _profile_row_to_dict(profile_row)
|
||||||
|
|
||||||
anns = conn.execute(
|
anns = conn.execute(
|
||||||
"SELECT * FROM announcements WHERE status IN ('청약예정', '청약중')"
|
"SELECT * FROM announcements WHERE status IN ('청약예정', '청약중', '결과발표')"
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
|
||||||
for ann_row in anns:
|
for ann_row in anns:
|
||||||
@@ -233,10 +235,10 @@ def run_matching():
|
|||||||
json.dumps(result["score_breakdown"]),
|
json.dumps(result["score_breakdown"]),
|
||||||
))
|
))
|
||||||
|
|
||||||
# Clean up stale match results for completed announcements
|
# 완료 상태 공고의 매칭 결과만 삭제 (결과발표는 보존)
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"DELETE FROM match_results WHERE announcement_id NOT IN "
|
"DELETE FROM match_results WHERE announcement_id IN "
|
||||||
"(SELECT id FROM announcements WHERE status IN ('청약예정', '청약중'))"
|
"(SELECT id FROM announcements WHERE status = '완료')"
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("매칭 완료")
|
logger.info("매칭 완료")
|
||||||
|
|||||||
Reference in New Issue
Block a user