fix: polling fallback когда SSE done event не доходит до клиента
Проблема: Claude Code Docker завершается, файлы на диске есть, но SSE event 'done' не доходит до браузера через nginx. UI зависает навечно. Решение: двойная страховка 1. JS: после завершения SSE stream поллит /api/batch-v2/status каждые 2с 2. API status: проверяет файлы на диске, если job.status ещё "uploaded" но batch_script.py уже существует → переводит в "analyzed" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+30
-4
@@ -192,11 +192,37 @@ async function startAnalysis() {
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
document.getElementById('analyze-spinner').style.display = 'none';
|
||||
stopTimer();
|
||||
document.getElementById('analyze-status').textContent = 'Ошибка: ' + e.message;
|
||||
document.getElementById('analyze-status').style.color = 'var(--accent)';
|
||||
// Network error or stream closed — ignore, fall through to polling
|
||||
}
|
||||
|
||||
// Fallback: if SSE ended without 'done' event, poll status
|
||||
if (!document.getElementById('step-confirm').classList.contains('hidden')) return; // already shown
|
||||
stopTimer();
|
||||
document.getElementById('analyze-status').textContent = 'Проверяю результат...';
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
try {
|
||||
const sr = await fetch('/api/batch-v2/status/' + jobId, {headers: H});
|
||||
const sd = await sr.json();
|
||||
if (sd.status === 'analyzed' && sd.script) {
|
||||
document.getElementById('analyze-spinner').style.display = 'none';
|
||||
document.getElementById('analyze-status').textContent = 'Анализ завершён';
|
||||
document.getElementById('script-code').textContent = sd.script;
|
||||
// Fetch summary from status if available
|
||||
renderSummary(sd.summary || {});
|
||||
show('step-confirm');
|
||||
return;
|
||||
} else if (sd.status === 'analysis_failed') {
|
||||
document.getElementById('analyze-spinner').style.display = 'none';
|
||||
document.getElementById('analyze-status').textContent = 'Ошибка анализа';
|
||||
document.getElementById('analyze-status').style.color = 'var(--accent)';
|
||||
return;
|
||||
}
|
||||
} catch(e2) {}
|
||||
}
|
||||
document.getElementById('analyze-spinner').style.display = 'none';
|
||||
document.getElementById('analyze-status').textContent = 'Таймаут — попробуйте ещё раз';
|
||||
document.getElementById('analyze-status').style.color = 'var(--accent)';
|
||||
}
|
||||
|
||||
async function reanalyze() {
|
||||
|
||||
Reference in New Issue
Block a user