Speed up football refresh (batch 24) + skip caching on API errors

develop
jwkim 2026-06-15 16:08:30 +09:00
parent 4246ad6936
commit dc262009f9
2 changed files with 10 additions and 3 deletions

View File

@ -118,8 +118,9 @@ class Settings(BaseSettings):
football_api_base: str = "https://v3.football.api-sports.io"
# 캐시 신선도(시간). 이 시간 지난 팀만 워커가 재수집(랭킹/폼은 자주 안 변함).
football_cache_ttl_hours: int = 168 # 7일
# 수집 잡 1회당 갱신할 최대 팀 수(무료 100/일·10/분 제한 분산).
football_refresh_batch: int = 8
# 수집 잡 1회당 갱신할 최대 팀 수. 팀당 ~3콜이라 24팀≈72콜(무료 100/일 안).
# 24면 48팀이 약 2일에 채워짐(8이면 6일). 한도 소진 시 남은 팀은 다음 잡에서.
football_refresh_batch: int = 24
# API 호출 간 최소 간격(초) — 무료 10req/분 제한 회피.
football_call_interval_sec: float = 7.0
# 수집 잡 시각(KST) — 예측 생성(00:05)보다 앞서 캐시를 채워둔다.

View File

@ -87,8 +87,14 @@ async def _get(client: httpx.AsyncClient, path: str, **params) -> dict:
timeout=25,
)
r.raise_for_status()
data = r.json()
# API-Football 은 한도초과·레이트·파라미터 오류를 HTTP 200 + errors 로 준다.
# 빈 응답을 정상으로 오해해 빈 데이터를 캐싱하지 않도록 여기서 예외 발생.
errs = data.get("errors")
if errs: # 빈 리스트([])는 정상, 채워진 dict 면 오류
raise RuntimeError(f"API-Football error: {errs}")
await asyncio.sleep(settings.football_call_interval_sec) # 10/분 제한 회피
return r.json()
return data
# ── 캐시 upsert ────────────────────────────────────────────────