feat(phase-1a): external data fetchers + refresh pipeline + scheduler
10종목 시드 + pykrx OHLCV / 외인·기관 거래대금, KIS read-only EOD, OpenDART
공시, 네이버 금융 뉴스 스크레이퍼, 구글 뉴스 RSS, yfinance 거시(KOSPI/KOSDAQ/
USDKRW/US10Y) fetcher 를 추가하고 refresh_one / daily_batch / backfill /
APScheduler(16:00 KST) 파이프라인으로 묶음.
- backend/app/seed: 10종목 시드 (대형/고변동/테마/플랫폼/방어)
- backend/app/fetch: pykrx, kis, dart, news, macro, symbols_seed
- backend/app/pipelines: refresh_one, daily_batch, backfill(CLI), scheduler
- backend/app/api/refresh.py: POST /api/refresh/{code}?lookback_days=N
- backend/app/main.py: lifespan 으로 스케줄러 기동/종료, /health/keys 추가
- README: .env 복사 안내 보강
스모크 테스트 (실제 키 사용) 결과:
KIS token : ok (token 346자 발급)
KIS daily : 005930 11rows
DART list : 005930 30일 10건
Naver news : 005930 12건
Google RSS : "삼성전자" 92건
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
46
backend/app/pipelines/scheduler.py
Normal file
46
backend/app/pipelines/scheduler.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""APScheduler 기반 백그라운드 잡.
|
||||
|
||||
- 16:00 KST : daily_batch
|
||||
- (Phase 4) 16:30: 모델 추론, 02:00 일요일: 주간 재학습
|
||||
|
||||
FastAPI 기동 시점에 lifespan 으로 start, 종료 시 shutdown.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from pytz import timezone
|
||||
|
||||
from app.pipelines.daily_batch import run_daily_batch
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
KST = timezone("Asia/Seoul")
|
||||
|
||||
_scheduler: BackgroundScheduler | None = None
|
||||
|
||||
|
||||
def start_scheduler() -> BackgroundScheduler:
|
||||
global _scheduler
|
||||
if _scheduler:
|
||||
return _scheduler
|
||||
_scheduler = BackgroundScheduler(timezone=KST)
|
||||
_scheduler.add_job(
|
||||
run_daily_batch,
|
||||
CronTrigger(hour=16, minute=0, timezone=KST),
|
||||
id="daily_batch_16",
|
||||
replace_existing=True,
|
||||
max_instances=1,
|
||||
)
|
||||
_scheduler.start()
|
||||
logger.info("scheduler started (daily_batch @ 16:00 KST)")
|
||||
return _scheduler
|
||||
|
||||
|
||||
def shutdown_scheduler() -> None:
|
||||
global _scheduler
|
||||
if _scheduler:
|
||||
_scheduler.shutdown(wait=False)
|
||||
_scheduler = None
|
||||
logger.info("scheduler stopped")
|
||||
Reference in New Issue
Block a user