()
| 935 | } |
| 936 | |
| 937 | async function pauseActiveBatchTasks() { |
| 938 | const tasks = getPausableBatchTasks(); |
| 939 | if (!tasks.length || isTaskPausing) return; |
| 940 | |
| 941 | isTaskPausing = true; |
| 942 | updateBatchButtons(); |
| 943 | try { |
| 944 | const results = await Promise.allSettled( |
| 945 | tasks.map((task) => api.post(`/tasks/${task.domain}/${task.id}/pause`, {}, { |
| 946 | timeoutMs: 15000, |
| 947 | retry: 0, |
| 948 | priority: 'high', |
| 949 | })), |
| 950 | ); |
| 951 | let successCount = 0; |
| 952 | let failedCount = 0; |
| 953 | results.forEach((item, index) => { |
| 954 | if (item.status === 'fulfilled') { |
| 955 | successCount += 1; |
| 956 | patchBatchTask(tasks[index].key, { |
| 957 | status: 'paused', |
| 958 | paused: true, |
| 959 | pause_requested: true, |
| 960 | }); |
| 961 | return; |
| 962 | } |
| 963 | failedCount += 1; |
| 964 | }); |
| 965 | if (successCount > 0) { |
| 966 | toast.success(`已暂停 ${successCount} 个任务`); |
| 967 | } |
| 968 | if (failedCount > 0) { |
| 969 | toast.warning(`${failedCount} 个任务暂停失败`); |
| 970 | } |
| 971 | } catch (error) { |
| 972 | toast.error(`暂停任务失败: ${error.message}`); |
| 973 | } finally { |
| 974 | isTaskPausing = false; |
| 975 | updateBatchButtons(); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | async function resumeActiveBatchTasks() { |
| 980 | const tasks = getResumableBatchTasks(); |
nothing calls this directly
no test coverage detected