feat(realestate): wire cleanup + notifier into scheduled flow
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,9 +12,11 @@ from .db import (
|
|||||||
update_all_statuses,
|
update_all_statuses,
|
||||||
get_profile, upsert_profile, get_matches, mark_match_read,
|
get_profile, upsert_profile, get_matches, mark_match_read,
|
||||||
get_last_collect_log, get_dashboard,
|
get_last_collect_log, get_dashboard,
|
||||||
|
delete_old_completed_announcements,
|
||||||
)
|
)
|
||||||
from .collector import collect_all
|
from .collector import collect_all
|
||||||
from .matcher import run_matching
|
from .matcher import run_matching
|
||||||
|
from .notifier import notify_new_matches
|
||||||
from .models import AnnouncementCreate, AnnouncementUpdate, ProfileUpdate
|
from .models import AnnouncementCreate, AnnouncementUpdate, ProfileUpdate
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(name)s] %(levelname)s %(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(name)s] %(levelname)s %(message)s")
|
||||||
@@ -24,11 +26,15 @@ scheduler = BackgroundScheduler(timezone=os.getenv("TZ", "Asia/Seoul"))
|
|||||||
|
|
||||||
|
|
||||||
def scheduled_collect():
|
def scheduled_collect():
|
||||||
"""매일 09:00 — 수집 + 매칭"""
|
"""매일 09:00 — 수집 + 정리 + 매칭 + 알림 push"""
|
||||||
logger.info("스케줄 수집 시작")
|
logger.info("스케줄 수집 시작")
|
||||||
collect_all()
|
collect_all()
|
||||||
|
deleted = delete_old_completed_announcements(grace_days=90)
|
||||||
|
if deleted:
|
||||||
|
logger.info("정리: %d건 삭제", deleted)
|
||||||
run_matching()
|
run_matching()
|
||||||
logger.info("스케줄 수집 + 매칭 완료")
|
notify_new_matches()
|
||||||
|
logger.info("스케줄 수집 + 매칭 + 알림 완료")
|
||||||
|
|
||||||
|
|
||||||
def scheduled_status_update():
|
def scheduled_status_update():
|
||||||
@@ -137,7 +143,9 @@ def _run_collect_and_match():
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
collect_all()
|
collect_all()
|
||||||
|
delete_old_completed_announcements(grace_days=90)
|
||||||
run_matching()
|
run_matching()
|
||||||
|
notify_new_matches()
|
||||||
finally:
|
finally:
|
||||||
_collect_lock.release()
|
_collect_lock.release()
|
||||||
|
|
||||||
|
|||||||
30
realestate-lab/tests/test_scheduled_flow.py
Normal file
30
realestate-lab/tests/test_scheduled_flow.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
|
def test_scheduled_collect_calls_cleanup_and_notifier():
|
||||||
|
from app import main as app_main
|
||||||
|
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
def fake_collect():
|
||||||
|
calls.append("collect")
|
||||||
|
return {"new_count": 0, "total_count": 0}
|
||||||
|
|
||||||
|
def fake_cleanup(grace_days=90):
|
||||||
|
calls.append(("cleanup", grace_days))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def fake_match():
|
||||||
|
calls.append("match")
|
||||||
|
|
||||||
|
def fake_notify():
|
||||||
|
calls.append("notify")
|
||||||
|
return {"sent": 0}
|
||||||
|
|
||||||
|
with patch.object(app_main, "collect_all", side_effect=fake_collect), \
|
||||||
|
patch.object(app_main, "delete_old_completed_announcements", side_effect=fake_cleanup), \
|
||||||
|
patch.object(app_main, "run_matching", side_effect=fake_match), \
|
||||||
|
patch.object(app_main, "notify_new_matches", side_effect=fake_notify):
|
||||||
|
app_main.scheduled_collect()
|
||||||
|
|
||||||
|
assert calls == ["collect", ("cleanup", 90), "match", "notify"]
|
||||||
Reference in New Issue
Block a user