(payload, count, sourceLabel, options = {})
| 1207 | } |
| 1208 | |
| 1209 | async function runBatchValidateTask(payload, count, sourceLabel, options = {}) { |
| 1210 | const showToast = options.showToast !== false; |
| 1211 | const reloadAfter = options.reloadAfter !== false; |
| 1212 | const onProgress = typeof options.onProgress === 'function' ? options.onProgress : null; |
| 1213 | isBatchValidating = true; |
| 1214 | updateBatchButtons(); |
| 1215 | elements.batchValidateBtn.textContent = '验证中...'; |
| 1216 | |
| 1217 | try { |
| 1218 | const task = await api.post('/accounts/batch-validate/async', payload, { |
| 1219 | timeoutMs: 20000, |
| 1220 | retry: 0, |
| 1221 | requestKey: 'accounts:batch-validate:async', |
| 1222 | cancelPrevious: true, |
| 1223 | }); |
| 1224 | const taskId = task?.id; |
| 1225 | if (!taskId) { |
| 1226 | throw new Error('任务创建失败:未返回任务 ID'); |
| 1227 | } |
| 1228 | trackBatchTask('validate', { |
| 1229 | id: taskId, |
| 1230 | domain: 'accounts', |
| 1231 | status: task?.status || 'pending', |
| 1232 | paused: Boolean(task?.paused), |
| 1233 | }); |
| 1234 | |
| 1235 | if (showToast) { |
| 1236 | toast.info(`${sourceLabel}任务已启动(${taskId.slice(0, 8)})`); |
| 1237 | } |
| 1238 | |
| 1239 | const finalTask = await watchAccountTask(taskId, (progressTask) => { |
| 1240 | patchBatchTask('validate', { |
| 1241 | status: progressTask?.status || 'running', |
| 1242 | paused: Boolean(progressTask?.paused), |
| 1243 | pause_requested: Boolean(progressTask?.pause_requested), |
| 1244 | }); |
| 1245 | const progress = progressTask?.progress || {}; |
| 1246 | const completed = Number(progress.completed || 0); |
| 1247 | const total = Number(progress.total || count); |
| 1248 | const paused = Boolean(progressTask?.paused) || String(progressTask?.status || '').toLowerCase() === 'paused'; |
| 1249 | elements.batchValidateBtn.textContent = paused ? `已暂停 ${completed}/${total}` : `验证中 ${completed}/${total}`; |
| 1250 | applyValidatedStatuses(progressTask); |
| 1251 | if (onProgress) { |
| 1252 | onProgress({ completed, total, task: progressTask }); |
| 1253 | } |
| 1254 | }); |
| 1255 | patchBatchTask('validate', { |
| 1256 | status: finalTask?.status || 'completed', |
| 1257 | paused: false, |
| 1258 | pause_requested: false, |
| 1259 | }); |
| 1260 | |
| 1261 | const result = finalTask?.result || {}; |
| 1262 | const status = String(finalTask?.status || '').toLowerCase(); |
| 1263 | if (status === 'completed') { |
| 1264 | if (showToast) { |
| 1265 | const workers = Number(result.worker_count || 0); |
| 1266 | const retries = Number(result.retry_count || 0); |
no test coverage detected