perf: 优化任务执行速度 (40-70s → ~15s)

问题:容错机制引入了大量叠加的等待时间

优化内容:
- playwright_automation.py:
  - 登录超时 30s → 10s
  - 导航等待 2s → 0.5s
  - navigate_only 等待 1s → 0.3s
  - 首页轮询 8次×3s → networkidle + 2次×0.5s
- services/tasks.py:
  - 删除截图前固定 sleep(2)
- services/screenshots.py:
  - networkidle 超时 30s → 10s
  - selector 超时 20s → 5s

预计性能提升:从 40-70 秒降至约 15 秒

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-24 00:19:46 +08:00
parent 79a571e58d
commit 1d44859857
3 changed files with 16 additions and 23 deletions

View File

@@ -130,11 +130,11 @@ def take_screenshot_for_account(
if "center.aspx" not in current_url:
raise RuntimeError(f"unexpected_iframe_url:{current_url}")
try:
iframe.wait_for_load_state("networkidle", timeout=30000)
iframe.wait_for_load_state("networkidle", timeout=10000)
except Exception:
pass
try:
iframe.wait_for_selector("table.ltable", timeout=20000)
iframe.wait_for_selector("table.ltable", timeout=5000)
except Exception:
pass
else:
@@ -144,11 +144,11 @@ def take_screenshot_for_account(
if "center.aspx" not in current_url:
raise RuntimeError(f"unexpected_url:{current_url}")
try:
automation.main_page.wait_for_load_state("networkidle", timeout=30000)
automation.main_page.wait_for_load_state("networkidle", timeout=10000)
except Exception:
pass
try:
automation.main_page.wait_for_selector("table.ltable", timeout=20000)
automation.main_page.wait_for_selector("table.ltable", timeout=5000)
except Exception:
pass
navigated = True