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

Method create_transfer_task

mod/project/node/dbutil/node_task_flow.py:950–1006  ·  view source on GitHub ↗
(
            self, flow_id: int, step_index: int, task_data: dict,
            nodes: List[Dict], used_nodes: List[Dict])

Source from the content-addressed store, hash-verified

948 return cmd_task, ""
949
950 def create_transfer_task(
951 self, flow_id: int, step_index: int, task_data: dict,
952 nodes: List[Dict], used_nodes: List[Dict]) -> Tuple[Optional[TransferTask], str]:
953
954 src_node_id = task_data.get('src_node_id', 0)
955 for node in used_nodes:
956 if node["id"] == src_node_id:
957 src_node = node
958 break
959 else:
960 return None, "源节点不存在"
961
962 path_list = task_data.get('path_list', [])
963 for p in path_list:
964 if "path" not in p or "dst_path" not in p or "is_dir" not in p:
965 return None, "文件分发规则错误"
966 if not path_list:
967 return None, "请选择文件"
968
969 dst_nodes = {
970 node["id"]: {
971 "name": node["remarks"], "address": node["address"],
972 "api_key": node["api_key"], "app_key": node["app_key"],
973 "ssh_conf": node["ssh_conf"], "lpver": node["lpver"],
974 "id": node["id"]
975 }
976 for node in nodes if node["id"] != src_node_id
977 }
978
979 tt = TransferTask(
980 name=task_data.get('name', random_name()),
981 flow_id=flow_id,
982 step_index=step_index,
983 src_node={"name": "local"},
984 src_node_task_id=0,
985 dst_nodes=dst_nodes,
986 path_list=task_data.get('path_list', []),
987 )
988
989 if not (src_node["app_key"] == "local" and src_node["api_key"] == "local"):
990 from mod.project.node.nodeutil import ServerNode
991 srv = ServerNode(src_node["address"], src_node["api_key"], src_node["app_key"])
992 res = srv.node_create_transfer_task(tt.to_dict())
993 if "task_id" in res.get("data", {}):
994 tt.src_node_task_id = res["data"]["task_id"]
995 tt.src_node = {
996 "name": src_node["remarks"], "address": src_node["address"],
997 "api_key": src_node["api_key"], "app_key": src_node["app_key"],
998 "lpver": src_node["lpver"]
999 }
1000
1001 task_id = self.TransferTask.create(tt)
1002 if not isinstance(task_id, int):
1003 return None, str(task_id)
1004
1005 tt.id = task_id
1006 return tt, ""
1007

Callers 1

create_flowMethod · 0.95

Calls 7

to_dictMethod · 0.95
ServerNodeClass · 0.90
TransferTaskClass · 0.85
random_nameFunction · 0.85
getMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected