(payload, count, sourceLabel, options = {})
| 1403 | } |
| 1404 | |
| 1405 | async function runOverviewRefreshTask(payload, count, sourceLabel, options = {}) { |
| 1406 | const showToast = options.showToast !== false; |
| 1407 | const reloadAfter = options.reloadAfter !== false; |
| 1408 | const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null; |
| 1409 | isOverviewRefreshing = true; |
| 1410 | updateBatchButtons(); |
| 1411 | |
| 1412 | try { |
| 1413 | const task = await api.post('/accounts/overview/refresh/async', payload, { |
| 1414 | timeoutMs: 20000, |
| 1415 | retry: 0, |
| 1416 | requestKey: 'accounts:overview-refresh', |
| 1417 | cancelPrevious: true, |
| 1418 | }); |
| 1419 | const taskId = task?.id; |
| 1420 | if (!taskId) { |
| 1421 | throw new Error('任务创建失败:未返回任务 ID'); |
| 1422 | } |
| 1423 | trackBatchTask('overview', { |
| 1424 | id: taskId, |
| 1425 | domain: 'accounts', |
| 1426 | status: task?.status || 'pending', |
| 1427 | paused: Boolean(task?.paused), |
| 1428 | }); |
| 1429 | if (showToast) { |
| 1430 | toast.info(`${sourceLabel}任务已启动(${taskId.slice(0, 8)})`); |
| 1431 | } |
| 1432 | |
| 1433 | const finalTask = await watchAccountTask(taskId, (progressTask) => { |
| 1434 | patchBatchTask('overview', { |
| 1435 | status: progressTask?.status || 'running', |
| 1436 | paused: Boolean(progressTask?.paused), |
| 1437 | pause_requested: Boolean(progressTask?.pause_requested), |
| 1438 | }); |
| 1439 | const progress = progressTask?.progress || {}; |
| 1440 | const completed = Number(progress.completed || 0); |
| 1441 | const total = Number(progress.total || count); |
| 1442 | if (onProgress) { |
| 1443 | onProgress({ completed, total, task: progressTask }); |
| 1444 | } |
| 1445 | }); |
| 1446 | patchBatchTask('overview', { |
| 1447 | status: finalTask?.status || 'completed', |
| 1448 | paused: false, |
| 1449 | pause_requested: false, |
| 1450 | }); |
| 1451 | const result = finalTask?.result || {}; |
| 1452 | const status = String(finalTask?.status || '').toLowerCase(); |
| 1453 | |
| 1454 | if (status === 'completed') { |
| 1455 | if (showToast) { |
| 1456 | toast.success(`总览刷新完成:成功 ${result.success_count || 0},失败 ${result.failed_count || 0}`); |
| 1457 | } |
| 1458 | } else if (status === 'cancelled') { |
| 1459 | if (showToast) { |
| 1460 | toast.warning(`任务已取消(成功 ${result.success_count || 0},失败 ${result.failed_count || 0})`, 5000); |
| 1461 | } |
| 1462 | } else if (showToast) { |
nothing calls this directly
no test coverage detected