Refactor reservation preemption handling and logging
- Removed the reservation preempt minimum value from the Runner and GUI components. - Updated logging mechanism to streamline log message handling and improve readability. - Introduced a new method for appending log lines in the Runner class. - Cleaned up related GUI elements and configuration options in web interface. - Deleted obsolete simulation scripts related to reservation preemption checks.
This commit is contained in:
1 parent
eb96d6869e
commit
93d47a16d6
20 files changed
+786
-1051
No files matched your search
+35
-25
@@ -106,7 +106,6 @@ class RunParams:
|
||||
high_value_room_revisit_only_current_run: bool
|
||||
reservation_back_verify_enabled: bool
|
||||
reservation_back_swipe_delay: float
|
||||
reservation_preempt_min_value: float
|
||||
fudai_find_max_attempts: int
|
||||
enable_ocr_mode1: bool
|
||||
fudai_template_match_enabled: bool
|
||||
@@ -123,6 +122,8 @@ class Runner:
|
||||
self._on_line = on_line
|
||||
self._reader_thread: Optional[threading.Thread] = None
|
||||
self._lock = threading.Lock()
|
||||
self._log: list[str] = []
|
||||
self._log_capacity: int = 4000
|
||||
|
||||
# 统计相关
|
||||
self._start_ts: Optional[float] = None
|
||||
@@ -157,6 +158,19 @@ class Runner:
|
||||
def is_running(self) -> bool:
|
||||
return self._proc is not None and self._proc.poll() is None
|
||||
|
||||
def _append_log_line(self, line: str) -> None:
|
||||
if line is None:
|
||||
return
|
||||
with self._lock:
|
||||
self._log.append(line)
|
||||
cap = self._log_capacity
|
||||
if cap > 0 and len(self._log) > cap:
|
||||
del self._log[: len(self._log) - cap]
|
||||
|
||||
def _emit_line(self, line: str) -> None:
|
||||
self._append_log_line(line)
|
||||
self._on_line(line)
|
||||
|
||||
def _inc(self, key: str, n: int = 1) -> None:
|
||||
with self._lock:
|
||||
self._counters[key] = int(self._counters.get(key, 0)) + int(n)
|
||||
@@ -962,13 +976,6 @@ class Runner:
|
||||
str(params.reservation_back_swipe_delay),
|
||||
]
|
||||
|
||||
# 预约抢占最小价值
|
||||
if params.reservation_preempt_min_value > 0:
|
||||
cmd += [
|
||||
"--reservation-preempt-min-value",
|
||||
str(params.reservation_preempt_min_value),
|
||||
]
|
||||
|
||||
# 找福袋最大尝试次数
|
||||
if params.fudai_find_max_attempts > 0:
|
||||
cmd += ["--fudai-find-max-attempts", str(params.fudai_find_max_attempts)]
|
||||
@@ -1023,7 +1030,7 @@ class Runner:
|
||||
env["PATH"] = adb_dir + os.pathsep + env.get("PATH", "")
|
||||
env["ADB_EXECUTABLE"] = adb_exe
|
||||
else:
|
||||
self._on_line(
|
||||
self._emit_line(
|
||||
"[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH"
|
||||
)
|
||||
|
||||
@@ -1069,6 +1076,7 @@ class Runner:
|
||||
}
|
||||
self._events = []
|
||||
self._wins = []
|
||||
self._log = []
|
||||
|
||||
def _reader():
|
||||
assert self._proc is not None
|
||||
@@ -1081,7 +1089,7 @@ class Runner:
|
||||
for line in out:
|
||||
has_output = True
|
||||
cleaned_line = line.rstrip("\n")
|
||||
self._on_line(cleaned_line)
|
||||
self._emit_line(cleaned_line)
|
||||
try:
|
||||
self._update_stats_from_line(cleaned_line)
|
||||
except Exception:
|
||||
@@ -1094,21 +1102,23 @@ class Runner:
|
||||
|
||||
# 如果进程立即退出且没有输出,说明可能有问题
|
||||
if not has_output and rc != 0:
|
||||
self._on_line(f"[警告] 进程立即退出,退出码={rc},没有输出")
|
||||
self._on_line(
|
||||
self._emit_line(
|
||||
f"[警告] 进程立即退出,退出码={rc},没有输出"
|
||||
)
|
||||
self._emit_line(
|
||||
"[提示] 可能的原因:run_cli.py启动失败、导入错误或配置错误"
|
||||
)
|
||||
else:
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
self._emit_line(f"[进程结束] exit_code={rc}")
|
||||
except Exception as e:
|
||||
# 读取输出时出错
|
||||
try:
|
||||
self._on_line(f"[错误] 读取进程输出失败: {e}")
|
||||
self._emit_line(f"[错误] 读取进程输出失败: {e}")
|
||||
rc = self._proc.poll()
|
||||
if rc is not None:
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
self._emit_line(f"[进程结束] exit_code={rc}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1131,14 +1141,14 @@ class Runner:
|
||||
try:
|
||||
adb_exe = find_adb_executable()
|
||||
if not adb_exe:
|
||||
self._on_line("[错误] 未找到 adb.exe")
|
||||
self._emit_line("[错误] 未找到 adb.exe")
|
||||
return False
|
||||
|
||||
# 如果没有指定设备ID,尝试获取第一个可用设备
|
||||
if not device_id or device_id.strip() == "":
|
||||
devices = list_adb_devices(adb_exe)
|
||||
if not devices:
|
||||
self._on_line("[错误] 未找到可用设备")
|
||||
self._emit_line("[错误] 未找到可用设备")
|
||||
return False
|
||||
device_id = devices[0]
|
||||
|
||||
@@ -1155,29 +1165,29 @@ class Runner:
|
||||
)
|
||||
|
||||
if proc.returncode == 0:
|
||||
self._on_line(f"[手动操作] 已发送返回键到设备: {device_id}")
|
||||
self._emit_line(f"[手动操作] 已发送返回键到设备: {device_id}")
|
||||
return True
|
||||
else:
|
||||
error_msg = proc.stderr or proc.stdout or "未知错误"
|
||||
self._on_line(f"[错误] 发送返回键失败: {error_msg}")
|
||||
self._emit_line(f"[错误] 发送返回键失败: {error_msg}")
|
||||
return False
|
||||
except subprocess.TimeoutExpired:
|
||||
self._on_line("[错误] 发送返回键超时")
|
||||
self._emit_line("[错误] 发送返回键超时")
|
||||
return False
|
||||
except Exception as e:
|
||||
self._on_line(f"[错误] 发送返回键异常: {str(e)}")
|
||||
self._emit_line(f"[错误] 发送返回键异常: {str(e)}")
|
||||
return False
|
||||
|
||||
def stop(self) -> None:
|
||||
if not self.is_running():
|
||||
return
|
||||
assert self._proc is not None
|
||||
self._on_line("[停止] 正在终止进程...")
|
||||
self._emit_line("[停止] 正在终止进程...")
|
||||
self._proc.terminate()
|
||||
try:
|
||||
self._proc.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
self._on_line("[停止] 进程未退出,强制结束...")
|
||||
self._emit_line("[停止] 进程未退出,强制结束...")
|
||||
self._proc.kill()
|
||||
|
||||
def force_stop(self) -> None:
|
||||
@@ -1186,10 +1196,10 @@ class Runner:
|
||||
pid = self._pid
|
||||
proc = self._proc
|
||||
if not pid and not proc:
|
||||
self._on_line("[停止] 当前无记录中的运行进程")
|
||||
self._emit_line("[停止] 当前无记录中的运行进程")
|
||||
return
|
||||
|
||||
self._on_line(f"[停止] 强制终止进程 (pid={pid}) ...")
|
||||
self._emit_line(f"[停止] 强制终止进程 (pid={pid}) ...")
|
||||
|
||||
# 先尝试通过 Popen 对象 kill
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user