mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
fix(agent): bound chat shutdown cancellation
This commit is contained in:
@@ -197,7 +197,9 @@ async def shutdown_web_agent_background_tasks() -> None:
|
||||
for task in tasks:
|
||||
task.cancel()
|
||||
if tasks:
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
# asyncio.wait 不会因关闭阶段自身被取消而再次取消这些任务;仍在收尾的
|
||||
# Agent 任务会保留在注册表中,直到自己的数据库操作取得确定终态。
|
||||
await asyncio.wait(tasks)
|
||||
|
||||
|
||||
def register_channel_admin_resolver(
|
||||
|
||||
@@ -389,6 +389,10 @@ class AgentChatPersistenceService:
|
||||
self._session_locks[session_id] = lock
|
||||
return lock
|
||||
|
||||
def begin_shutdown(self) -> None:
|
||||
"""停止接受新的 AgentChat 持久化任务。"""
|
||||
self._closing = True
|
||||
|
||||
async def _run_write(
|
||||
self,
|
||||
session_id: str,
|
||||
@@ -436,11 +440,13 @@ class AgentChatPersistenceService:
|
||||
|
||||
async def shutdown(self) -> None:
|
||||
"""拒绝新写入并等待当前会话锁和 worker 操作取得终态。"""
|
||||
self._closing = True
|
||||
self.begin_shutdown()
|
||||
current = asyncio.current_task()
|
||||
tasks = tuple(task for task in self._active_tasks if task is not current)
|
||||
if tasks:
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
# wait 不会在生命周期超时时取消实际写入;外层可及时返回并保留
|
||||
# 数据库 worker owner,已开始的事务继续由 worker 收口。
|
||||
await asyncio.wait(tasks)
|
||||
|
||||
async def async_append_display_messages(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user