// book 43 轮询监控 - 每 60 秒查询一次状态 const { PrismaClient } = require('@prisma/client'); const p = new PrismaClient(); const START = Date.now(); const MAX_MS = 90 * 60 * 1000; // 90 分钟 const LOG_FILE = '/tmp/poll-book43-v2.log'; const fs = require('fs'); function log(msg) { const ts = new Date().toISOString(); const line = `[${ts}] ${msg}\n`; fs.appendFileSync(LOG_FILE, line); process.stdout.write(line); } // 清理旧日志 fs.writeFileSync(LOG_FILE, `=== 轮询开始 ${new Date().toISOString()} ===\n`); async function tick() { const elapsed = Math.floor((Date.now() - START) / 1000); try { const b = await p.book.findUnique({ where: { id: 43 }, select: { genStage: true, progress: true, failedStage: true, errorMsg: true, outlineJson: true, bookAnalysis: true, updatedAt: true } }); const outlineLen = (b.outlineJson || '').length; const analysisLen = (b.bookAnalysis || '').length; const stage = b.genStage; const prog = b.progress; const failed = b.failedStage; const err = b.errorMsg ? b.errorMsg.substring(0, 120) : null; log(`[${elapsed}s] ${stage}|${prog}|${failed}|${outlineLen}|${analysisLen}|err=${err || '-'}`); // 终态检测 if (stage === 'failed' && failed) { log(`!!! 检测到失败: stage=${failed}, errorMsg=${err}`); log(`!!! 等待 Coding Agent 处理`); // 继续监控但放慢 } if (stage === 'content_completed' || stage === 'audio_completed' || prog >= 100) { log(`🎉 完成! genStage=${stage}, progress=${prog}`); process.exit(0); } } catch (e) { log(`[error] ${e.message}`); } if (Date.now() - START > MAX_MS) { log(`!!! 轮询超时 90 分钟,退出`); process.exit(2); } setTimeout(tick, 60000); } tick();