fix: retry launch page.goto to absorb transient DNS/timeout
Third launch failure this session (after two 顺心 load-timeouts and a 中通 ERR_NAME_NOT_RESOLVED) — each a transient network blip that killed the whole worker because launch_and_prepare opened sites with no retry. Wrap each site open+goto in _open_page: up to 3 attempts (2s apart) on domcontentloaded, so transient DNS/timeout is absorbed; only persistent failure (all 3) aborts. All 5 sites + 安能 now launch clean. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -299,23 +299,39 @@ def launch_and_prepare(debug_mode=False, debug_target=""):
|
||||
print("\n====================================================")
|
||||
print("【启动】正在打开各站点页面...")
|
||||
print("====================================================")
|
||||
|
||||
def _open_page(label, attempts=3):
|
||||
"""开一个页面并 goto(url, domcontentloaded);容忍瞬时 DNS/超时抖动重试,全失败才抛。
|
||||
domcontentloaded:DOM 就绪即返回,不等慢资源(广告/图片)的 load 事件,
|
||||
避免某站 load 超 30s / 瞬时 DNS 失败导致整个 worker 启动失败。就绪轮询自会判登录态。"""
|
||||
last = None
|
||||
for i in range(1, attempts + 1):
|
||||
pg = context.new_page()
|
||||
try:
|
||||
pg.goto(url, wait_until="domcontentloaded")
|
||||
return pg
|
||||
except Exception as e:
|
||||
last = e
|
||||
try:
|
||||
pg.close()
|
||||
except Exception:
|
||||
pass
|
||||
print(f"⚠️ 打开【{label}】第 {i}/{attempts} 次失败: {e}")
|
||||
if i < attempts:
|
||||
time.sleep(2)
|
||||
raise RuntimeError(f"打开【{label}】连续 {attempts} 次失败: {last}")
|
||||
|
||||
for site_name, url in active_sites.items():
|
||||
if site_name == "顺心":
|
||||
# 顺心:两个归属地账号在同一窗口各开一个标签页
|
||||
sx_pages = []
|
||||
for acct in range(1, 3):
|
||||
print(f">> 正在启动【顺心】账号{acct}标签页: {url}")
|
||||
sx_page = context.new_page()
|
||||
# domcontentloaded:DOM 就绪即返回,不等慢资源(广告/图片)的 load 事件,
|
||||
# 避免顺心等站点 load 超 30s 导致整个 worker 启动失败。就绪轮询自会判登录态。
|
||||
sx_page.goto(url, wait_until="domcontentloaded")
|
||||
sx_pages.append(sx_page)
|
||||
sx_pages.append(_open_page(f"顺心账号{acct}"))
|
||||
pages_map["顺心"] = sx_pages
|
||||
else:
|
||||
print(f">> 正在启动【{site_name}】页面: {url}")
|
||||
page = context.new_page()
|
||||
page.goto(url, wait_until="domcontentloaded")
|
||||
pages_map[site_name] = page
|
||||
pages_map[site_name] = _open_page(site_name)
|
||||
|
||||
# 4. 安能 Electron
|
||||
anneng_proc = None
|
||||
|
||||
Reference in New Issue
Block a user