MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / startLogPolling

Function startLogPolling

static/js/app.js:1561–1617  ·  view source on GitHub ↗
(taskUuid)

Source from the content-addressed store, hash-verified

1559
1560// 开始轮询日志
1561function startLogPolling(taskUuid) {
1562 if (logPollingInterval) {
1563 return;
1564 }
1565
1566 let lastLogIndex = 0;
1567
1568 logPollingInterval = setInterval(async () => {
1569 try {
1570 const data = await api.get(`/registration/tasks/${taskUuid}/logs`);
1571
1572 // 更新任务状态
1573 updateTaskStatus(data.status);
1574
1575 // 更新邮箱信息
1576 if (data.email) {
1577 elements.taskEmail.textContent = data.email;
1578 }
1579 if (data.email_service) {
1580 elements.taskService.textContent = getServiceTypeText(data.email_service);
1581 }
1582
1583 // 添加新日志
1584 const logs = data.logs || [];
1585 for (let i = lastLogIndex; i < logs.length; i++) {
1586 const log = logs[i];
1587 const logType = getLogType(log);
1588 addLog(logType, log);
1589 }
1590 lastLogIndex = logs.length;
1591
1592 // 检查任务是否完成
1593 if (['completed', 'failed', 'cancelled'].includes(data.status)) {
1594 stopLogPolling();
1595 resetButtons();
1596
1597 // 只显示一次 toast
1598 if (!toastShown) {
1599 toastShown = true;
1600 if (data.status === 'completed') {
1601 addLog('success', '[成功] 注册成功!');
1602 toast.success('注册成功!');
1603 // 刷新账号列表
1604 loadRecentAccounts();
1605 } else if (data.status === 'failed') {
1606 addLog('error', '[错误] 注册失败');
1607 toast.error('注册失败');
1608 } else if (data.status === 'cancelled') {
1609 addLog('warning', '[警告] 任务已取消');
1610 }
1611 }
1612 }
1613 } catch (error) {
1614 console.error('轮询日志失败:', error);
1615 }
1616 }, 1000);
1617}
1618

Callers 1

connectWebSocketFunction · 0.85

Calls 10

updateTaskStatusFunction · 0.85
getServiceTypeTextFunction · 0.85
getLogTypeFunction · 0.85
addLogFunction · 0.85
stopLogPollingFunction · 0.85
resetButtonsFunction · 0.85
loadRecentAccountsFunction · 0.85
successMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected