调整插件执行模式并修复全球新闻后台线程
1. 为消息插件新增按消息动态超时能力,并让机器人侧按当前命令读取超时策略。 2. 将斗鱼日报、身价关系图/重算、百科问答出题判题切到后台执行。 3. 将系统更新、黑丝视频、猛男视频、成员锐评默认配置为后台模式并放宽超时。 4. 修复全球新闻插件在线程中直接挂协程导致任务不真正执行的问题。
This commit is contained in:
26
robot.py
26
robot.py
@@ -674,7 +674,7 @@ class Robot:
|
||||
|
||||
# 检查插件是否可以处理该消息
|
||||
if plugin.can_process(plugin_msg):
|
||||
protection_policy = self._build_message_plugin_protection_policy(plugin)
|
||||
protection_policy = self._build_message_plugin_protection_policy(plugin, plugin_msg)
|
||||
acquire_result = self.plugin_manager.try_acquire_plugin_execution(
|
||||
plugin,
|
||||
recovery_seconds=protection_policy["circuit_recovery_seconds"],
|
||||
@@ -819,7 +819,7 @@ class Robot:
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
def _build_message_plugin_protection_policy(self, plugin) -> dict:
|
||||
def _build_message_plugin_protection_policy(self, plugin, plugin_msg: dict = None) -> dict:
|
||||
"""构建消息插件执行保护策略。"""
|
||||
plugin_config = getattr(plugin, "_config", {}) or {}
|
||||
runtime_config = plugin_config.get("runtime", {}) if isinstance(plugin_config, dict) else {}
|
||||
@@ -827,12 +827,32 @@ class Robot:
|
||||
breaker_config = runtime_config.get("circuit_breaker", {}) if isinstance(runtime_config, dict) else {}
|
||||
breaker_config = breaker_config if isinstance(breaker_config, dict) else {}
|
||||
|
||||
dynamic_timeout = 0
|
||||
if plugin_msg and hasattr(plugin, "get_message_process_timeout_seconds"):
|
||||
try:
|
||||
# 允许插件按“当前消息内容”给出更精细的超时建议:
|
||||
# 1. 同一个插件里,日报/渲染/重算命令往往比普通查询慢很多;
|
||||
# 2. 以前只能给整个插件统一配一个超时,容易出现“轻命令超时过大、重命令超时不够”的两难;
|
||||
# 3. 这里把粒度放到单条消息,便于插件只给真正的长任务放宽保护时间。
|
||||
dynamic_timeout = self._safe_positive_int(
|
||||
plugin.get_message_process_timeout_seconds(plugin_msg),
|
||||
0,
|
||||
)
|
||||
except Exception as e:
|
||||
self.LOG.warning(
|
||||
self._trace_message(
|
||||
plugin_msg.get("full_wx_msg"),
|
||||
f"读取插件动态超时失败,已回退默认策略: plugin={plugin.name}, error={e}"
|
||||
)
|
||||
)
|
||||
|
||||
# 超时策略尽量遵循“显式配置优先,已有内部超时参数兜底”的思路:
|
||||
# 1. 新插件如果有特殊需求,只需要在 runtime / circuit_breaker 下声明自己的超时;
|
||||
# 2. 老插件不改代码也能自动复用现有的 request / llm / render 超时字段;
|
||||
# 3. 最终统一加一个缓冲区,避免外层 wait_for 比插件内部自己的超时还更早打断。
|
||||
explicit_timeout = (
|
||||
runtime_config.get("plugin_process_timeout_seconds")
|
||||
dynamic_timeout
|
||||
or runtime_config.get("plugin_process_timeout_seconds")
|
||||
or runtime_config.get("message_timeout_seconds")
|
||||
or breaker_config.get("timeout_seconds")
|
||||
or getattr(plugin, "plugin_process_timeout_seconds", 0)
|
||||
|
||||
Reference in New Issue
Block a user