import logging import uuid from typing import Any from pydantic import ValidationError from app.celery import celery_app from app.config import settings from app.fandata.types import FanBatch from app.pipeline.fan_collect import collect from app.pipeline.fan_fanout import fanout logger = logging.getLogger(__name__) def _fan_collect(body: dict[str, Any]) -> None: try: batch = FanBatch.model_validate(body) except ValidationError: logger.exception("Invalid fan_collect message body — skipping") return collect(batch=batch) @celery_app.task( name="fan_collect_spotify_smf", max_retries=0, time_limit=settings.fan_collect_time_limit_s, ) def fan_collect_spotify_smf(body: dict[str, Any]) -> None: _fan_collect(body) @celery_app.task( name="fan_collect_spotify_songwhip", max_retries=0, time_limit=settings.fan_collect_time_limit_s, ) def fan_collect_spotify_songwhip(body: dict[str, Any]) -> None: _fan_collect(body) @celery_app.task( name="fan_fanout", max_retries=0, time_limit=settings.fan_fanout_time_limit_s, ) def fan_fanout(run_id: str) -> None: fanout(run_id=uuid.UUID(run_id))