mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 05:42:39 +02:00
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:
parent
b79befdef6
commit
d76da8a59d
1 changed files with 12 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
"""Celery tasks for podcast generation."""
|
"""Celery tasks for podcast generation."""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||||
from sqlalchemy.pool import NullPool
|
from sqlalchemy.pool import NullPool
|
||||||
|
|
@ -11,6 +13,14 @@ from app.tasks.podcast_tasks import generate_chat_podcast
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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():
|
def get_celery_session_maker():
|
||||||
"""
|
"""
|
||||||
|
|
@ -39,8 +49,6 @@ def generate_chat_podcast_task(
|
||||||
podcast_title: Title for the podcast
|
podcast_title: Title for the podcast
|
||||||
user_id: ID of the user
|
user_id: ID of the user
|
||||||
"""
|
"""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
|
|
||||||
|
|
@ -48,7 +56,9 @@ def generate_chat_podcast_task(
|
||||||
loop.run_until_complete(
|
loop.run_until_complete(
|
||||||
_generate_chat_podcast(chat_id, search_space_id, podcast_title, user_id)
|
_generate_chat_podcast(chat_id, search_space_id, podcast_title, user_id)
|
||||||
)
|
)
|
||||||
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||||
finally:
|
finally:
|
||||||
|
asyncio.set_event_loop(None)
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue