diff --git a/realestate-lab/app/main.py b/realestate-lab/app/main.py index d436058..b7e6105 100644 --- a/realestate-lab/app/main.py +++ b/realestate-lab/app/main.py @@ -12,9 +12,11 @@ from .db import ( update_all_statuses, get_profile, upsert_profile, get_matches, mark_match_read, get_last_collect_log, get_dashboard, + delete_old_completed_announcements, ) from .collector import collect_all from .matcher import run_matching +from .notifier import notify_new_matches from .models import AnnouncementCreate, AnnouncementUpdate, ProfileUpdate 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(): - """매일 09:00 — 수집 + 매칭""" + """매일 09:00 — 수집 + 정리 + 매칭 + 알림 push""" logger.info("스케줄 수집 시작") collect_all() + deleted = delete_old_completed_announcements(grace_days=90) + if deleted: + logger.info("정리: %d건 삭제", deleted) run_matching() - logger.info("스케줄 수집 + 매칭 완료") + notify_new_matches() + logger.info("스케줄 수집 + 매칭 + 알림 완료") def scheduled_status_update(): @@ -137,7 +143,9 @@ def _run_collect_and_match(): return try: collect_all() + delete_old_completed_announcements(grace_days=90) run_matching() + notify_new_matches() finally: _collect_lock.release() diff --git a/realestate-lab/tests/test_scheduled_flow.py b/realestate-lab/tests/test_scheduled_flow.py new file mode 100644 index 0000000..f0b39cf --- /dev/null +++ b/realestate-lab/tests/test_scheduled_flow.py @@ -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"]