fix: podcast tasks for Windows compatibility

- Added WindowsProactorEventLoopPolicy for better async subprocess support on Windows.
- Ensured proper cleanup of the event loop after task execution.
- Removed redundant asyncio import from the generate_chat_podcast_task function.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-10-30 12:05:06 -07:00
parent b79befdef6
commit d76da8a59d

View file

@ -1,6 +1,8 @@
"""Celery tasks for podcast generation."""
import asyncio
import logging
import sys
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy.pool import NullPool
@ -11,6 +13,14 @@ from app.tasks.podcast_tasks import generate_chat_podcast
logger = logging.getLogger(__name__)
if sys.platform.startswith("win"):
try:
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
except AttributeError:
logger.warning(
"WindowsProactorEventLoopPolicy is unavailable; async subprocess support may fail."
)
def get_celery_session_maker():
"""
@ -39,8 +49,6 @@ def generate_chat_podcast_task(
podcast_title: Title for the podcast
user_id: ID of the user
"""
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
@ -48,7 +56,9 @@ def generate_chat_podcast_task(
loop.run_until_complete(
_generate_chat_podcast(chat_id, search_space_id, podcast_title, user_id)
)
loop.run_until_complete(loop.shutdown_asyncgens())
finally:
asyncio.set_event_loop(None)
loop.close()