Revert "为长任务插件接入后台任务模式"

This reverts commit 0d1362f97e.
This commit is contained in:
Liu
2026-05-01 12:45:34 +08:00
parent 08db0ea07e
commit e75fe04b77
7 changed files with 78 additions and 351 deletions

View File

@@ -7,20 +7,6 @@ from utils.robot_cmd.robot_command import Feature
class MessagePluginInterface(PluginInterface):
"""消息处理插件接口"""
@staticmethod
def normalize_message_dispatch_mode(raw_mode: Any) -> str:
"""把插件声明的消息分发模式标准化为 `sync` 或 `background`。
设计说明:
1. `sync` 表示沿用当前主链路同步执行,插件会占用当前消息处理协程直到完成;
2. `background` 表示命中后立即转入后台任务池,主消息链路尽快释放,不再占用前台并发槽位;
3. 这里集中做别名兼容,后续插件只需要写 `background/async/queue` 这类语义值即可。
"""
mode = str(raw_mode or "").strip().lower()
if mode in {"background", "async", "queued", "queue", "detached"}:
return "background"
return "sync"
@property
def command_prefix(self) -> Optional[str]:
"""命令前缀,如 '/'"""
@@ -87,20 +73,6 @@ class MessagePluginInterface(PluginInterface):
"""
raise NotImplementedError("子类必须实现此方法")
def get_message_dispatch_mode(self, message: Dict[str, Any]) -> str:
"""返回当前消息应采用的执行模式。
默认行为:
1. 优先读取插件自身 `config.toml` 里的 `[runtime] message_dispatch_mode`
2. 若未配置,则回退为 `sync`,保持历史行为不变;
3. 长任务插件如果需要“按命令动态切换前后台”,可以在子类中覆盖本方法。
"""
plugin_config = getattr(self, "_config", {}) or {}
runtime_config = plugin_config.get("runtime", {}) if isinstance(plugin_config, dict) else {}
runtime_config = runtime_config if isinstance(runtime_config, dict) else {}
raw_mode = runtime_config.get("message_dispatch_mode") or runtime_config.get("dispatch_mode") or "sync"
return self.normalize_message_dispatch_mode(raw_mode)
# ---------------- 插件定时调度能力(可选实现) ----------------
def get_schedule_actions(self) -> List[Dict[str, Any]]:
"""返回插件支持的可调度动作定义列表。