chore: sync current WechatHookBot workspace
This commit is contained in:
@@ -183,17 +183,25 @@ class EventManager:
|
||||
start_time = time.time()
|
||||
all_completed = True
|
||||
|
||||
logger.debug(
|
||||
f"[EventManager] 触发: {event_type}, "
|
||||
f"处理器数量: {len(handlers)}"
|
||||
)
|
||||
# logger.debug(
|
||||
# f"[EventManager] 触发: {event_type}, "
|
||||
# f"处理器数量: {len(handlers)}"
|
||||
# )
|
||||
|
||||
performance_monitor = None
|
||||
try:
|
||||
from utils.bot_utils import get_performance_monitor
|
||||
performance_monitor = get_performance_monitor()
|
||||
except Exception:
|
||||
performance_monitor = None
|
||||
|
||||
for handler_info in handlers:
|
||||
stats.handler_calls += 1
|
||||
success = True
|
||||
handler_start = time.perf_counter()
|
||||
|
||||
try:
|
||||
logger.debug(f"[EventManager] 调用: {handler_info.handler_name}")
|
||||
|
||||
# logger.debug(f"[EventManager] 调用: {handler_info.handler_name}")
|
||||
result = await handler_info.handler(*args, **kwargs)
|
||||
|
||||
# 检查是否中断
|
||||
@@ -207,12 +215,21 @@ class EventManager:
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
success = False
|
||||
stats.error_count += 1
|
||||
logger.error(
|
||||
f"[EventManager] {handler_info.handler_name} 执行失败: {e}"
|
||||
)
|
||||
logger.debug(f"详细错误:\n{traceback.format_exc()}")
|
||||
# 继续执行其他处理器
|
||||
finally:
|
||||
if performance_monitor:
|
||||
handler_elapsed = time.perf_counter() - handler_start
|
||||
performance_monitor.record_plugin_execution(
|
||||
handler_info.instance.__class__.__name__,
|
||||
handler_elapsed,
|
||||
success
|
||||
)
|
||||
|
||||
elapsed_ms = (time.time() - start_time) * 1000
|
||||
stats.total_time_ms += elapsed_ms
|
||||
@@ -247,13 +264,31 @@ class EventManager:
|
||||
|
||||
semaphore = asyncio.Semaphore(max_concurrency)
|
||||
|
||||
performance_monitor = None
|
||||
try:
|
||||
from utils.bot_utils import get_performance_monitor
|
||||
performance_monitor = get_performance_monitor()
|
||||
except Exception:
|
||||
performance_monitor = None
|
||||
|
||||
async def run_handler(handler_info: HandlerInfo):
|
||||
async with semaphore:
|
||||
success = True
|
||||
handler_start = time.perf_counter()
|
||||
try:
|
||||
return await handler_info.handler(*args, **kwargs)
|
||||
except Exception as e:
|
||||
success = False
|
||||
logger.error(f"[EventManager] {handler_info.handler_name} 失败: {e}")
|
||||
return None
|
||||
finally:
|
||||
if performance_monitor:
|
||||
handler_elapsed = time.perf_counter() - handler_start
|
||||
performance_monitor.record_plugin_execution(
|
||||
handler_info.instance.__class__.__name__,
|
||||
handler_elapsed,
|
||||
success
|
||||
)
|
||||
|
||||
tasks = [run_handler(h) for h in handlers]
|
||||
return await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
Reference in New Issue
Block a user