Commit 3b49d654 authored by 郭阔's avatar 郭阔

feat(panel): recycle browser instance after login test

- platform.sh: new nh_quit_instance <source> — quits the site-shared instance
  after panel login tests; skips when a harvest holds the port runlock
- app.py: login-test / login-test-src / login-discover background threads now
  recycle the instance when the test finishes (login state lives in profile,
  unaffected); manual-login flow (ensure-chromium --login) intentionally left open
parent 155faf6a
...@@ -410,6 +410,23 @@ nh_ensure_instance() { # <source> 确保该源所属站点共享浏览器实例 ...@@ -410,6 +410,23 @@ nh_ensure_instance() { # <source> 确保该源所属站点共享浏览器实例
return 0 return 0
} }
nh_quit_instance() { # <source> 回收该源所属站点的共享浏览器实例(幂等;登录态在 profile 不受影响)
# 供面板"测试登录/自动配置配方"结束后调用;有采集任务占用该端口(runlock)时跳过,
# 人工登录专用流程(ensure-chromium.js --login)不经过本函数,窗口保持打开。
local source="$1" skill_dir site port lockdir
skill_dir="$(nh_skill_dir 2>/dev/null)" || return 0
[ -f "$skill_dir/scripts/instance-quit.js" ] || return 0
site="$(nh_login_site "$source")"
port="$(nh_cdp_port "$site")"
lockdir="$(nh_default_work_dir)/runlocks"
if ls "$lockdir"/port-"$port".*.lock >/dev/null 2>&1; then
echo "端口 $port 实例正被采集任务占用,跳过回收"
return 0
fi
CDP_PORT_OVERRIDE="$port" node "$skill_dir/scripts/instance-quit.js" 2>&1 | sed 's/^/ [instance] /'
return 0
}
nh_login_preflight() { # <source> nh_login_preflight() { # <source>
local source="$1" creds tools_dir local source="$1" creds tools_dir
creds="$(nh_login_creds_file "$source" || true)" creds="$(nh_login_creds_file "$source" || true)"
......
...@@ -1048,6 +1048,8 @@ def login_discover(site): ...@@ -1048,6 +1048,8 @@ def login_discover(site):
"output": ((out or "") + (("\n" + err) if err else ""))[-2000:], "output": ((out or "") + (("\n" + err) if err else ""))[-2000:],
"start": _login_test[site]["start"], "start": _login_test[site]["start"],
} }
# 测试完回收站点实例(登录态在 profile;有采集占用时函数内部自动跳过)
call_platform("nh_quit_instance", probe)
threading.Thread(target=_run, daemon=True).start() threading.Thread(target=_run, daemon=True).start()
flash(f"站点 {site} 自动配置配方并测试已启动(入口 {probe},约 30-120 秒,页面自动刷新)", "success") flash(f"站点 {site} 自动配置配方并测试已启动(入口 {probe},约 30-120 秒,页面自动刷新)", "success")
...@@ -1076,6 +1078,8 @@ def login_test(site): ...@@ -1076,6 +1078,8 @@ def login_test(site):
"output": ((out or "") + (("\n" + err) if err else ""))[-2000:], "output": ((out or "") + (("\n" + err) if err else ""))[-2000:],
"start": _login_test[site]["start"], "start": _login_test[site]["start"],
} }
# 测试完回收站点实例(登录态在 profile;有采集占用时函数内部自动跳过)
call_platform("nh_quit_instance", probe)
threading.Thread(target=_run, daemon=True).start() threading.Thread(target=_run, daemon=True).start()
flash(f"站点 {site} 登录测试已启动(入口 {probe},约 10-60 秒,页面自动刷新显示结果)", "success") flash(f"站点 {site} 登录测试已启动(入口 {probe},约 10-60 秒,页面自动刷新显示结果)", "success")
...@@ -1105,6 +1109,8 @@ def login_test_source(source): ...@@ -1105,6 +1109,8 @@ def login_test_source(source):
"output": ((out or "") + (("\n" + err) if err else ""))[-2000:], "output": ((out or "") + (("\n" + err) if err else ""))[-2000:],
"start": _login_test[source]["start"], "start": _login_test[source]["start"],
} }
# 测试完回收站点共享实例(登录态在 profile;有采集占用时函数内部自动跳过)
call_platform("nh_quit_instance", source)
threading.Thread(target=_run, daemon=True).start() threading.Thread(target=_run, daemon=True).start()
flash(f"源 {source} 登录测试已启动(拉起其所属站点 {source.split('-')[0]} 的共享实例,约 10-60 秒,页面自动刷新显示结果)", "success") flash(f"源 {source} 登录测试已启动(拉起其所属站点 {source.split('-')[0]} 的共享实例,约 10-60 秒,页面自动刷新显示结果)", "success")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment