49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""
|
|
VideoReaction Write-Behind 플러시 잡
|
|
|
|
1분마다 백엔드 내부 API를 호출하여 Redis dirty SET의 좋아요 토글을 MySQL에 반영합니다.
|
|
"""
|
|
|
|
import logging
|
|
|
|
import httpx
|
|
|
|
from config import settings
|
|
from jobs.base import BaseJob
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ReactionFlushJob(BaseJob):
|
|
name = "VideoReaction 플러시"
|
|
|
|
async def run(self) -> None:
|
|
logger.info("[REACTION_FLUSH] 플러시 시작")
|
|
|
|
try:
|
|
async with httpx.AsyncClient() as client:
|
|
response = await client.post(
|
|
f"{settings.BACKEND_INTERNAL_URL}/internal/video/reactions/flush",
|
|
headers={"X-Internal-Secret": settings.INTERNAL_SECRET_KEY},
|
|
timeout=30.0,
|
|
)
|
|
response.raise_for_status()
|
|
|
|
result = response.json()
|
|
logger.info(
|
|
f"[REACTION_FLUSH] SUCCESS - "
|
|
f"flushed: {result.get('flushed', 0)}, "
|
|
f"adds: {result.get('adds', 0)}, "
|
|
f"dels: {result.get('dels', 0)}"
|
|
)
|
|
|
|
except httpx.HTTPStatusError as e:
|
|
logger.error(
|
|
f"[REACTION_FLUSH] HTTP 오류 - "
|
|
f"status: {e.response.status_code}, body: {e.response.text}"
|
|
)
|
|
except httpx.RequestError as e:
|
|
logger.error(f"[REACTION_FLUSH] 요청 오류 - error: {e}")
|
|
except Exception as e:
|
|
logger.error(f"[REACTION_FLUSH] EXCEPTION - error: {e}")
|