# Conflicts: # backend/router/v1/index/index.py # backend/services/calc/index_calc.py # backend/services/index_service.py # backend/tests/conftest.py # backend/tests/test_index_api.py # backend/tests/test_index_calc.py # backend/tests/test_sky_api.py # backend/worker_main.py
40 lines
1.5 KiB
Python
40 lines
1.5 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_weekend_rank, refresh_openmeteo_weather
|
|
|
|
|
|
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)
|
|
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, 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())
|