from __future__ import annotations import logging from typing import Optional, Dict, Any from celery import shared_task from apps.podcast.services.rss_importer import sync_podcast_rss logger = logging.getLogger(__name__) @shared_task(name='apps.podcast.tasks.sync_podcast_rss_task') def sync_podcast_rss_task(playlist_id: Optional[int] = None, feed_url: Optional[str] = None) -> Dict[str, Any]: """ Celery task to sync podcasts from RSS feed. Can be run periodically by Celery Beat or triggered on-demand from the admin panel. """ logger.info(f"Running sync_podcast_rss_task (playlist_id={playlist_id}, feed_url={feed_url})") try: result = sync_podcast_rss(playlist_id=playlist_id, feed_url=feed_url) logger.info(f"sync_podcast_rss_task finished successfully: {result}") return result except Exception as e: logger.error(f"sync_podcast_rss_task failed: {e}", exc_info=True) return {"status": "error", "error": str(e)}