将登录巡检能力收口到provider层
This commit is contained in:
@@ -33,7 +33,7 @@ def get_system_job_definitions(robot) -> List[Dict[str, Any]]:
|
||||
"description": "每天 14:43 执行登录二次校验",
|
||||
"trigger_type": "at_times",
|
||||
"trigger_config": {"time_list": ["14:43"]},
|
||||
"handler": robot.login_twice_auto_auth,
|
||||
"handler": _build_login_check_handler(robot),
|
||||
},
|
||||
{
|
||||
"job_key": "process_pending_images",
|
||||
@@ -75,6 +75,30 @@ def _build_contact_avatar_cache_sync_handler(robot) -> Callable[[], Awaitable[No
|
||||
return _handler
|
||||
|
||||
|
||||
def _build_login_check_handler(robot) -> Callable[[], Awaitable[bool]]:
|
||||
async def _handler() -> bool:
|
||||
ipad_bot = getattr(robot, "ipad_bot", None)
|
||||
if not ipad_bot:
|
||||
logger.info("系统任务 login_check 已跳过:wechat provider 尚未初始化")
|
||||
return False
|
||||
|
||||
login_health_check = getattr(ipad_bot, "run_login_health_check", None)
|
||||
if not callable(login_health_check):
|
||||
logger.info("系统任务 login_check 已跳过:当前 provider 未暴露登录巡检能力")
|
||||
return False
|
||||
|
||||
# 系统任务层只认 provider 统一入口:
|
||||
# 1. 这样“是否要做二次登录校验”由具体 provider 自己决定;
|
||||
# 2. Robot 不再残留 server 版本差异相关的旧方法;
|
||||
# 3. 后续新增 provider 时,只需实现自己的巡检逻辑即可接入现有调度链。
|
||||
result = login_health_check()
|
||||
if inspect.isawaitable(result):
|
||||
result = await result
|
||||
return bool(result)
|
||||
|
||||
return _handler
|
||||
|
||||
|
||||
class SystemJobLoader:
|
||||
"""系统任务加载器:从数据库读取调度配置并注册到 async_job。"""
|
||||
|
||||
|
||||
@@ -13,3 +13,13 @@ class WechatProviderBase(ABC):
|
||||
provider_name = "base"
|
||||
server_type = "base"
|
||||
|
||||
async def run_login_health_check(self) -> bool:
|
||||
"""执行 provider 自己定义的登录态巡检。
|
||||
|
||||
设计说明:
|
||||
1. 不同 provider 的登录维护方式差异很大,不能再把这类逻辑留在 Robot 业务层;
|
||||
2. 855 需要继续执行“二次登录校验”,864 当前则不依赖这套动作;
|
||||
3. 因此基类默认返回 False,表示“当前 provider 没有额外巡检动作”,具体实现由各 provider 自己覆盖。
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
@@ -46,6 +46,14 @@ class Legacy855WechatClient(
|
||||
MessageMixin.__init__(self)
|
||||
self._init_runtime_state()
|
||||
|
||||
async def run_login_health_check(self) -> bool:
|
||||
"""执行 855 provider 的登录态巡检。"""
|
||||
# 855 仍然保留“二次自动校验登录”的历史运维动作:
|
||||
# 1. 这项逻辑本来就属于 855 provider 的登录模型,不应该继续挂在 Robot 上;
|
||||
# 2. 这里直接复用 provider 内部现有 `twice_auto_auth` 能力,避免重新拆一套重复逻辑;
|
||||
# 3. 上层系统任务只需要调用统一入口,不再关心底层到底是 855 还是别的 server。
|
||||
return bool(await self.twice_auto_auth())
|
||||
|
||||
async def send_at_message(self, wxid: str, content: str, at: list[str]) -> tuple[int, int, int]:
|
||||
"""发送 @ 消息,兼容现有插件调用方式。"""
|
||||
if not self.wxid:
|
||||
|
||||
@@ -36,3 +36,11 @@ class Server864WechatClient(
|
||||
Server864APIClientBase.__init__(self, ip, port, server_key=server_key, **kwargs)
|
||||
MessageMixin.__init__(self)
|
||||
self._init_runtime_state()
|
||||
|
||||
async def run_login_health_check(self) -> bool:
|
||||
"""执行 864 provider 的登录态巡检。"""
|
||||
# 864 当前不依赖 855 那套“二次自动校验”模型:
|
||||
# 1. 登录状态更多由服务端维护,客户端不需要额外补一次旧版登录恢复动作;
|
||||
# 2. 因此这里显式返回 False,表示“本 provider 没有额外巡检动作”,避免系统任务报错;
|
||||
# 3. 后续如果 864 需要补自己的巡检逻辑,也只需要在本 provider 内部扩展。
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user