- FastAPI + PostgreSQL + Redis, web·worker 분리, compose 에 backend·worker·postgres·redis 추가 - 기상청 단기·초단기·중기·특보, 에어코리아, Open-Meteo, TourAPI, 특일정보 연동 (첫 조회 때 받고 캐시) - 매일 03:00 worker 가 전국 공통 피드 칸을 정하고 지난 데이터를 정리 - 시드: 시군구 256곳, 지수 23개, 노을 대표 지점·명소, 데이트 명소, 읽을거리 - pytest 66개 (테스트 전용 DB·Redis 사용) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
973 B
Python
36 lines
973 B
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
|
|
|
|
|
|
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)
|
|
scheduler.start()
|
|
LOG.info("[worker] started, daily job at 03:00 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())
|