feat(task-retry): 重试按钮推广到相似ASIN与采集数据

同类问题一起修:这两个模块与外观专利共用同一条自动重试(原先也克隆重试)。
- 新增通用端点 POST /api/tasks/{taskId}/retry(模块无关,从任务行取 moduleType)
- 两页失败任务在「删除」前显示「重试」,调用后在原任务上复位续跑
- catch 棘轮 308→310,两处均 ElMessage 可见出口
This commit is contained in:
2026-11-01 00:46:08 +08:00
parent 0a467793ac
commit 96b090dfd5
6 changed files with 133 additions and 1 deletions
@@ -120,11 +120,15 @@
history-empty-text="暂无历史记录"
>
<template #item-actions="{ item }">
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
<template #history-item-actions="{ item }">
<button v-if="canDownload(itemSource(item))" type="button" class="download"
@click="downloadResult(itemSource(item))">下载</button>
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button v-if="itemSource(item).resultId" type="button" class="btn-delete"
@click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
@@ -139,6 +143,7 @@
import { computed, onBeforeUnmount, onMounted, reactive, ref, shallowRef, triggerRef } from 'vue'
import { userNotice } from '@/shared/utils/user-notice'
import { ElMessage } from 'element-plus'
import { retryClientTask } from '@/shared/api/task-retry'
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
@@ -491,6 +496,26 @@ async function pushToPythonQueue() {
}
}
/**
* 失败任务重试:在**原任务**上复位续跑(不新建任务),与外观专利同口径。
* 只有 FAILED 才出按钮——成功/进行中的任务重试没有语义。
*/
function canRetryTask(item: CollectDataHistoryItem | null | undefined): boolean {
return Boolean(item?.taskId) && normalizeTaskStatus(item as CollectDataHistoryItem) === 'FAILED'
}
async function retryTaskRecord(item: CollectDataHistoryItem | null | undefined) {
const taskId = item?.taskId
if (!taskId) return
try {
await retryClientTask(taskId)
ElMessage.success('已提交重试:在这条任务上继续跑(不新建任务)')
await refreshBoard()
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '重试失败')
}
}
function normalizeTaskStatus(item: CollectDataHistoryItem) {
return (item.taskStatus || '').toUpperCase()
}
@@ -109,11 +109,15 @@
<div v-if="pendingResultHint(itemSource(item))" class="files result-hint">{{ pendingResultHint(itemSource(item)) }}</div>
</template>
<template #item-actions="{ item }">
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button type="button" class="btn-delete" @click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
<template #history-item-actions="{ item }">
<button v-if="canDownload(itemSource(item))" type="button" class="download"
@click="downloadResult(itemSource(item))">下载</button>
<button v-if="canRetryTask(itemSource(item))" type="button" class="btn-retry"
@click="retryTaskRecord(itemSource(item))">重试</button>
<button v-if="itemSource(item).resultId" type="button" class="btn-delete"
@click="deleteTaskRecord(itemSource(item))">删除</button>
</template>
@@ -129,6 +133,7 @@
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { userNotice } from '@/shared/utils/user-notice'
import { ElMessage } from 'element-plus'
import { retryClientTask } from '@/shared/api/task-retry'
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue';
import FileUploadZone from '@/shared/components/FileUploadZone.vue'
import ModuleTemplateDownload from '@/shared/components/ModuleTemplateDownload.vue'
@@ -369,6 +374,26 @@ function isResultPreparing(item: SimilarAsinHistoryItem) {
return true
}
/**
* 失败任务重试:在**原任务**上复位续跑(不新建任务),与外观专利同口径。
* 只有 FAILED 才出按钮——成功/进行中的任务重试没有语义。
*/
function canRetryTask(item: SimilarAsinHistoryItem | null | undefined): boolean {
return Boolean(item?.taskId) && normalizeTaskStatus(item as SimilarAsinHistoryItem) === 'FAILED'
}
async function retryTaskRecord(item: SimilarAsinHistoryItem | null | undefined) {
const taskId = item?.taskId
if (!taskId) return
try {
await retryClientTask(taskId)
ElMessage.success('已提交重试:在这条任务上继续跑(不新建任务)')
await refreshBoard()
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '重试失败')
}
}
function normalizeTaskStatus(item: SimilarAsinHistoryItem) {
const taskStatus = (item.taskStatus || '').toUpperCase()
if (taskStatus !== 'FAILED' && isResultFileComplete(item)) return 'SUCCESS'
+18
View File
@@ -0,0 +1,18 @@
import { post, type JavaApiResponse, unwrapJavaResponse } from './http.ts'
import { JAVA_API_PREFIX } from './url.ts'
import { getCurrentUserId } from './user.ts'
/**
* 失败任务重试(模块无关,2026-11-01 用户拍板)。
*
* 口径:失败任务**不再自动克隆**(同一份输入会多出好几行结果),改由用户在「删除」旁点
* 「重试」——服务端在原任务上复位(FAILED→PENDING),保留已收分片、解析载荷与已检测标记,
* 也就是断点续传。外观专利/相似ASIN/采集数据三个模块共用这一条出口。
*/
export function retryClientTask(taskId: number) {
return unwrapJavaResponse(
post<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/tasks/${taskId}/retry`, undefined, {
params: { user_id: getCurrentUserId() },
}),
)
}