Files
o2o-weather/backend/worker_main.py
minaChoi 3f8f7daeb1 Merge origin/main into main-2: Open-Meteo 구름 20·100km·모델 2개 구조에 노을 하늘 상황 판정 맞춤
- 하늘 상황 판정·테스트를 구름 지점 2곳(20·100km), 모델 2개(JMA·ICON) 기준으로
- Open-Meteo 보조값 호출(fetch_weather)도 장애 대처(8초 끊기·2분 건너뛰기) 적용
- worker: 행사 수집 스케줄과 Open-Meteo 보조값 스케줄 둘 다 유지
- 지수 seed: main 의 한계 설명 + main-2 의 점수 구간 설명
- 옛 data-pipeline 문서는 삭제 유지, 내용은 openmeteo-data.md·데이터_흐름.html 에 반영
2026-10-07 14:04:18 +09:00

43 lines
1.9 KiB
Python

import asyncio
import signal
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from common.database.db_session_manager import DB_SESSION_MNG
from common.logger import LOG
from scheduler.jobs import build_today_feed, cleanup_old_rows, refresh_air_stations, refresh_events, refresh_openmeteo_weather, refresh_weekend_rank
async def daily() -> None:
await build_today_feed()
await cleanup_old_rows()
await refresh_air_stations()
async def main() -> None:
scheduler = AsyncIOScheduler(timezone="Asia/Seoul")
scheduler.add_job(daily, "cron", hour=3, minute=0, max_instances=1, coalesce=True)
# 주말 나들이 점수: 단기예보 05·17시 발표와 중기예보 06·18시 발표가 다 나온 뒤. 켤 때 캐시가 없으면 한 번.
scheduler.add_job(refresh_weekend_rank, "cron", hour="6,18", minute=40, max_instances=1, coalesce=True)
scheduler.add_job(refresh_weekend_rank, kwargs={"only_if_missing": True}, max_instances=1)
# 행사(축제·전시·콘서트·팝업): 7일에 한 번, 끝나면 Teams 알림. 켤 때 7일 안에 받은 기록이 없으면 한 번.
scheduler.add_job(refresh_events, "cron", day_of_week="mon", hour=4, minute=0, max_instances=1, coalesce=True)
scheduler.add_job(refresh_events, kwargs={"only_if_missing": True}, max_instances=1)
scheduler.add_job(refresh_openmeteo_weather, "cron", hour="3,9,15,21", minute=10, max_instances=1, coalesce=True)
scheduler.start()
LOG.info("[worker] started, daily job at 03:00 KST, weekend rank at 06:40·18:40 KST, events on Mon 04:00 KST, openmeteo job at 03·09·15·21:10 KST")
stop = asyncio.Event()
loop = asyncio.get_running_loop()
for sig in (signal.SIGINT, signal.SIGTERM):
loop.add_signal_handler(sig, stop.set)
await stop.wait()
scheduler.shutdown(wait=True)
await DB_SESSION_MNG.stop()
LOG.info("[worker] stopped")
if __name__ == "__main__":
asyncio.run(main())