chore(plugin): set hot-reload watcher interval to 60s

This commit is contained in:
liuwei
2026-04-16 13:57:37 +08:00
parent f0414e0dff
commit cb0d11e657
2 changed files with 8 additions and 3 deletions

View File

@@ -61,7 +61,8 @@ class PluginManager:
# 热加载相关
self._watcher_thread: Optional[threading.Thread] = None
self._watcher_stop_event = threading.Event()
self._watcher_interval = 2.0
# 默认每 60 秒扫描一次插件目录,降低线上资源消耗
self._watcher_interval = 60.0
self._module_file_state: Dict[str, Dict[str, float]] = {}
self._watcher_lock = threading.RLock()
@@ -132,9 +133,12 @@ class PluginManager:
except Exception as e:
self.LOG.error(f"自动注入 bot 到插件 {plugin.name} 失败: {e}")
def start_hot_reload_watcher(self, interval_seconds: float = 2.0):
def start_hot_reload_watcher(self, interval_seconds: float = 60.0):
"""
启动插件目录变更监听线程(轮询)
Args:
interval_seconds: 轮询间隔秒数,默认 60 秒
"""
with self._watcher_lock:
if self._watcher_thread and self._watcher_thread.is_alive():

View File

@@ -98,7 +98,8 @@ class Robot:
self.plugin_manager = PluginManager(plugin_dir=getattr(self.config, "plugin_dir", "plugins"))
self.plugin_manager.set_system_context(self.system_context)
self.plugins = self.plugin_manager.load_all_plugins()
self.plugin_manager.start_hot_reload_watcher(interval_seconds=2.0)
# 热加载改为低频扫描:每 60 秒检查一次插件文件变动
self.plugin_manager.start_hot_reload_watcher(interval_seconds=60.0)
# 加载插件
self.LOG.debug("插件系统初始化完成")