修复一些问题
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import threading
|
||||
from typing import Dict, Tuple
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from typing import Dict, Tuple, List
|
||||
from Utils.LogManager import LogManager
|
||||
|
||||
|
||||
@@ -64,6 +65,37 @@ class ThreadManager:
|
||||
LogManager.method_info(f"设备 {udid} 的任务停止成功", method="task")
|
||||
return 200, f"当前任务停止成功 {udid}"
|
||||
|
||||
@classmethod
|
||||
def batch_stop(cls, udids: List[str]) -> Tuple[int, List[str], str]:
|
||||
"""
|
||||
批量停止任务,使用多线程并发执行。
|
||||
:param udids: 待停止的设备唯一标识列表
|
||||
:return: (code, fail_list, msg)
|
||||
code=200 全部成功,fail_list=[]
|
||||
code=1001 部分/全部失败,fail_list 为失败描述字符串列表
|
||||
"""
|
||||
if not udids:
|
||||
return 200, [], "无设备需要停止"
|
||||
|
||||
fail_list: List[str] = []
|
||||
|
||||
with ThreadPoolExecutor(max_workers=min(32, len(udids))) as executor:
|
||||
future_map = {executor.submit(cls.stop, udid): udid for udid in udids}
|
||||
|
||||
for future in as_completed(future_map):
|
||||
udid = future_map[future]
|
||||
try:
|
||||
code, reason = future.result()
|
||||
if code != 200:
|
||||
fail_list.append(f"设备{udid}停止失败:{reason}")
|
||||
except Exception as exc:
|
||||
fail_list.append(f"设备{udid}停止异常:{exc}")
|
||||
|
||||
if fail_list:
|
||||
return 1001, fail_list, "停止失败"
|
||||
return 200, [], "全部设备停止成功"
|
||||
|
||||
|
||||
@classmethod
|
||||
def is_task_running(cls, udid: str) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user