- 各泳道真实参与方账号独立登录,每泳道 newContext() 缓存隔离 - SSE send() 吞客户端断开错误,避免污染服务端批次 - running 标志自愈 + finally 先释放,浏览器清理带超时 - 面板 open 默认 false,避免本机低内存 OOM 杀主浏览器与 BE - 新增 run_and_wait.mjs / trigger_run.mjs 触发+前台轮询 - 权限守卫机制与多用户根因沉淀;精简 MEMORY.md 至 3000 字符
73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
// 触发 DAG 批次并等待结果文件完成(不依赖 SSE 客户端存活)
|
|
// 用法: node run_and_wait.mjs [seqId]
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
const SEQ = process.argv[2] || 'seq-1'
|
|
const DAG_BASE = 'http://127.0.0.1:7789'
|
|
const RUNS_DIR = path.join(import.meta.dirname, 'results', 'dag-runs')
|
|
|
|
function readRun(runId) {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(path.join(RUNS_DIR, runId + '.json'), 'utf-8'))
|
|
} catch { return null }
|
|
}
|
|
|
|
async function main() {
|
|
// 1) 触发并拿到 runId(读到第一个 'start' 事件即断开客户端,服务端继续)
|
|
const ctrl = new AbortController()
|
|
const resp = await fetch(`${DAG_BASE}/api/run`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ seq: SEQ, open: false }),
|
|
signal: ctrl.signal
|
|
})
|
|
if (!resp.ok) {
|
|
const t = await resp.text()
|
|
console.log(`TRIGGER_FAIL http=${resp.status} ${t.slice(0, 200)}`)
|
|
process.exit(2)
|
|
}
|
|
const reader = resp.body.getReader()
|
|
const dec = new TextDecoder()
|
|
let buf = ''
|
|
let runId = null
|
|
const deadline = Date.now() + 20000
|
|
while (Date.now() < deadline) {
|
|
const { value, done } = await reader.read()
|
|
if (done) break
|
|
buf += dec.decode(value, { stream: true })
|
|
const m = buf.match(/runId["']?\s*[:"]\s*([0-9TZ-]+)/)
|
|
if (m) { runId = m[1]; break }
|
|
const m2 = buf.match(/event: start[^]*?runId["']?:\s*["']([0-9TZ-]+)["']/)
|
|
if (m2) { runId = m2[1]; break }
|
|
}
|
|
ctrl.abort() // 断开 SSE 客户端,服务端继续跑
|
|
console.log(`TRIGGERED seq=${SEQ} runId=${runId}`)
|
|
if (!runId) { console.log('NO_RUNID buf=', buf.slice(0, 300)); process.exit(3) }
|
|
|
|
// 2) 轮询结果文件直到 21 节点 + completedAt
|
|
const total = 21
|
|
let last = 0
|
|
for (let i = 0; i < 140; i++) {
|
|
const r = readRun(runId)
|
|
if (r) {
|
|
const n = r.nodes?.length || 0
|
|
if (n !== last) { last = n; console.log(` progress: ${n}/${total} nodes written`) }
|
|
if (r.completedAt) {
|
|
const s = r.summary || {}
|
|
console.log(`\n=== DONE runId=${runId} ===`)
|
|
console.log(`summary: pass=${s.pass} fail=${s.fail} elapsed=${r.elapsedMs}ms`)
|
|
for (const nd of r.nodes) {
|
|
const err = nd.error ? nd.error.slice(0, 95) : ''
|
|
console.log(` ${nd.id.padEnd(7)} ${String(nd.status).padEnd(5)} ${err}`)
|
|
}
|
|
process.exit(0)
|
|
}
|
|
}
|
|
await new Promise((res) => setTimeout(res, 5000))
|
|
}
|
|
console.log('TIMEOUT waiting for completion')
|
|
process.exit(4)
|
|
}
|
|
main().catch((e) => { console.log('ERR', e.message); process.exit(1) })
|