Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox_Bot into dev
This commit is contained in:
@@ -32,13 +32,10 @@ class SchedulerDispatcher:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
# 追踪每个流的 schedule_id
|
# 追踪每个流的 schedule_id
|
||||||
self.stream_schedules: dict[str, str] = {} # stream_id -> schedule_id
|
self.stream_schedules: dict[str, str] = {} # stream_id -> schedule_id
|
||||||
|
|
||||||
# 用于保护 schedule 创建/删除的锁,避免竞态条件
|
|
||||||
self.schedule_locks: dict[str, asyncio.Lock] = {} # stream_id -> Lock
|
|
||||||
|
|
||||||
# Chatter 管理器
|
# Chatter 管理器
|
||||||
self.chatter_manager: ChatterManager | None = None
|
self.chatter_manager: ChatterManager | None = None
|
||||||
|
|
||||||
# 统计信息
|
# 统计信息
|
||||||
self.stats = {
|
self.stats = {
|
||||||
"total_schedules_created": 0,
|
"total_schedules_created": 0,
|
||||||
@@ -85,12 +82,6 @@ class SchedulerDispatcher:
|
|||||||
self.chatter_manager = chatter_manager
|
self.chatter_manager = chatter_manager
|
||||||
logger.debug(f"设置 Chatter 管理器: {chatter_manager.__class__.__name__}")
|
logger.debug(f"设置 Chatter 管理器: {chatter_manager.__class__.__name__}")
|
||||||
|
|
||||||
def _get_schedule_lock(self, stream_id: str) -> asyncio.Lock:
|
|
||||||
"""获取流的 schedule 锁"""
|
|
||||||
if stream_id not in self.schedule_locks:
|
|
||||||
self.schedule_locks[stream_id] = asyncio.Lock()
|
|
||||||
return self.schedule_locks[stream_id]
|
|
||||||
|
|
||||||
async def on_message_received(self, stream_id: str) -> None:
|
async def on_message_received(self, stream_id: str) -> None:
|
||||||
"""消息接收时的处理逻辑
|
"""消息接收时的处理逻辑
|
||||||
|
|
||||||
@@ -121,7 +112,7 @@ class SchedulerDispatcher:
|
|||||||
should_interrupt = await self._check_interruption(stream_id, context)
|
should_interrupt = await self._check_interruption(stream_id, context)
|
||||||
|
|
||||||
if should_interrupt:
|
if should_interrupt:
|
||||||
# 移除旧 schedule 并创建新的(内部有锁保护)
|
# 移除旧 schedule 并创建新的
|
||||||
await self._cancel_and_recreate_schedule(stream_id, context)
|
await self._cancel_and_recreate_schedule(stream_id, context)
|
||||||
logger.debug(f"⚡ 打断成功: 流={stream_id[:8]}..., 已重新创建 schedule")
|
logger.debug(f"⚡ 打断成功: 流={stream_id[:8]}..., 已重新创建 schedule")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user