默认关闭插件热加载扫盘监听
This commit is contained in:
@@ -153,6 +153,20 @@ class Config(object):
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
@staticmethod
|
||||
def _safe_bool(value, default: bool):
|
||||
"""把常见的字符串/数字配置安全转成布尔值。"""
|
||||
if value is None:
|
||||
return default
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
text = str(value).strip().lower()
|
||||
if text in {"1", "true", "yes", "y", "on"}:
|
||||
return True
|
||||
if text in {"0", "false", "no", "n", "off"}:
|
||||
return False
|
||||
return default
|
||||
|
||||
def _normalize_config(self, yconfig: dict) -> dict:
|
||||
"""对解析后的配置做一次结构与类型归一化。"""
|
||||
normalized = copy.deepcopy(yconfig or {})
|
||||
@@ -180,6 +194,15 @@ class Config(object):
|
||||
email_config["smtp_port"] = self._safe_int(email_config.get("smtp_port", 465), 465)
|
||||
normalized["email_config"] = email_config
|
||||
|
||||
plugin_hot_reload = dict(normalized.get("plugin_hot_reload", {}) or {})
|
||||
# 插件热加载本质上是一个持续扫盘线程:
|
||||
# 1. 本地开发时它很方便,但线上稳定运行时意义不大;
|
||||
# 2. 用户当前明确希望先停掉这类自动扫盘行为,降低不必要的 IO 干扰;
|
||||
# 3. 因此这里把 enabled / interval_seconds 做成标准化配置,便于后续按环境开关。
|
||||
plugin_hot_reload["enabled"] = self._safe_bool(plugin_hot_reload.get("enabled", False), False)
|
||||
plugin_hot_reload["interval_seconds"] = self._safe_int(plugin_hot_reload.get("interval_seconds", 600), 600)
|
||||
normalized["plugin_hot_reload"] = plugin_hot_reload
|
||||
|
||||
return normalized
|
||||
|
||||
@classmethod
|
||||
@@ -423,6 +446,7 @@ class Config(object):
|
||||
# 后续如果逐步引入更严格的配置对象,也可以先不动业务代码。
|
||||
self.environment = str(self.resolved_config.get("environment", "development") or "development").strip()
|
||||
self.plugin_dir = str(self.resolved_config.get("plugin_dir", "plugins") or "plugins").strip()
|
||||
self.plugin_hot_reload = self.resolved_config.get("plugin_hot_reload", {})
|
||||
self.mariadb = self.resolved_config.get("db_config", {})
|
||||
self.redis = self.resolved_config.get("redis_config", {})
|
||||
self.email = self.resolved_config.get("email_config", {})
|
||||
|
||||
Reference in New Issue
Block a user