MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / monitor_node_once_with_timeout

Function monitor_node_once_with_timeout

mod/project/node/nodeutil/base.py:1133–1181  ·  view source on GitHub ↗
(node_data: dict, timeout: int = 5)

Source from the content-addressed store, hash-verified

1131
1132
1133def monitor_node_once_with_timeout(node_data: dict, timeout: int = 5):
1134 if node_data["app_key"] == "local" and node_data["api_key"] == "local":
1135 return
1136 from mod.project.node.dbutil import Node, ServerNodeDB, ServerMonitorRepo
1137 from mod.project.node.nodeutil.ssh_wrap import SSHApi
1138 try:
1139 node_data["error"] = json.loads(node_data["error"])
1140 node_data["ssh_conf"] = json.loads(node_data["ssh_conf"])
1141 node, err = Node.from_dict(node_data)
1142 if err:
1143 public.print_log("节点数据解析错误:{}".format(err))
1144 return
1145
1146 if node_data["app_key"] or node_data["api_key"]:
1147 node_data["timeout"] = timeout
1148 srv = ServerNode.new_by_data(node_data)
1149 node_data.pop("timeout")
1150 elif node_data["ssh_conf"]:
1151 srv = SSHApi(**node_data["ssh_conf"], timeout=timeout)
1152 else:
1153 return
1154
1155 data, err = srv.get_net_work()
1156 if err:
1157 node.error_num += 1
1158 node.error = {
1159 "msg": err,
1160 "time": int(time.time())
1161 }
1162 if node.error_num >= 2:
1163 node.status = 0
1164 ServerMonitorRepo().remove_cache(node.id)
1165
1166 ServerNodeDB().update_node(node)
1167
1168 elif node.error_num > 0:
1169 node.error_num = 0
1170 node.error = {}
1171 node.status = 1
1172 ServerNodeDB().update_node(node)
1173
1174 if data:
1175 repo = ServerMonitorRepo()
1176 repo.save_server_status(node.id, data)
1177 if repo.is_reboot_wait(node.server_ip):
1178 repo.set_wait_reboot(node.server_ip, False)
1179 except Exception as e:
1180 if public.is_debug():
1181 public.print_error()
1182
1183
1184class LocalNode(ServerNode):

Callers 2

add_nodeMethod · 0.90
update_nodeMethod · 0.90

Calls 15

get_net_workMethod · 0.95
save_server_statusMethod · 0.95
is_reboot_waitMethod · 0.95
set_wait_rebootMethod · 0.95
SSHApiClass · 0.90
ServerMonitorRepoClass · 0.90
ServerNodeDBClass · 0.90
new_by_dataMethod · 0.80
timeMethod · 0.80
loadsMethod · 0.45
from_dictMethod · 0.45
print_logMethod · 0.45

Tested by

no test coverage detected