fix: manage WebRTC pipeline shutdown
This commit is contained in:
@@ -169,6 +169,21 @@ class ConversationRecorder:
|
||||
logger.error(f"保存对话文本失败,不影响本次通话: {exc}")
|
||||
|
||||
async def finish(self, *, status: str = "completed") -> None:
|
||||
"""Finish the session even if the owning pipeline is being cancelled."""
|
||||
finish_task = asyncio.create_task(
|
||||
self._finish(status=status),
|
||||
name=f"conversation-recorder-finish:{self.session_id}",
|
||||
)
|
||||
try:
|
||||
await asyncio.shield(finish_task)
|
||||
except asyncio.CancelledError:
|
||||
# Shield prevents an interrupted pipeline cleanup from abandoning a
|
||||
# checked-out asyncpg connection. Preserve cancellation only after
|
||||
# the short database cleanup has returned the connection.
|
||||
await asyncio.shield(finish_task)
|
||||
raise
|
||||
|
||||
async def _finish(self, *, status: str) -> None:
|
||||
async with self._lock:
|
||||
try:
|
||||
async with SessionLocal() as db:
|
||||
|
||||
Reference in New Issue
Block a user