feat(brand): 失败任务「重新提交」入口+排队期显示执行方人话文案(3700 客户端半边)
- brand.ts:resubmitBrandTask 走桥 resubmit_brand_task(重跑必须本机客户端建单执行, 线上 15126 无从替用户重跑;老客户端 available=false 提示升级);BrandLocalBridge 登记 桥形状;BrandLineProgressInfo 补 progress_text 与 queued 档注释。 - BrandBrandTab.vue:failed/cancelled 行出「重新提交」按钮(确认框点名沿用策略与通道); 排队期 extraLines 显示 progress_text(已等待 N 秒;同机 M/K 槽在用),countLabel 不再 摆恒 0 的「0/265」——用户从「排队中/0 行」无从分辨排队与卡死。 - pywebview.ts:open_jd_login 注释改按自动链路口径(见下一笔,桥本身零改动)。 - 判据:brand-resubmit-entry.test.ts(桥形状+入口 wiring+源码绊线)+ task-progress-view-wiring.test.ts +排队文案透出绊线+catch-silence 台账 blocks 334→335 (resubmitTask 的 try/catch 有用户可见出口,非静默,silent 与 perFile 未动)。
This commit is contained in:
@@ -111,6 +111,8 @@
|
||||
</template>
|
||||
<template #history-item-actions="{ item }">
|
||||
<template v-if="itemSource(item)">
|
||||
<button v-if="canResubmit(itemSource(item))" type="button" class="download"
|
||||
@click="resubmitTask(itemSource(item))">重新提交</button>
|
||||
<button v-if="canDownload(itemSource(item))" type="button" class="download"
|
||||
@click="downloadResult(itemSource(item))">下载结果</button>
|
||||
<button v-if="canDelete(itemSource(item))" type="button" class="btn-delete"
|
||||
@@ -139,6 +141,7 @@ import {
|
||||
getBrandTask,
|
||||
getBrandTaskDownloadUrl,
|
||||
getBrandTasks,
|
||||
resubmitBrandTask,
|
||||
runBrandLocal,
|
||||
runBrandNow,
|
||||
type BrandTaskItem,
|
||||
@@ -205,7 +208,9 @@ const hasUid = computed(() => {
|
||||
const timers = createCategorizedTimers('brand-brand-task')
|
||||
let pollTimer: number | null = null
|
||||
/** taskId -> 行级进度快照(按“已处理品牌行 / 总品牌行”推进,成功或查询失败都计入完成数) */
|
||||
const lineProgressMap = ref<Record<string, { current: number; total: number; phase?: string }>>({})
|
||||
const lineProgressMap = ref<
|
||||
Record<string, { current: number; total: number; phase?: string; text?: string }>
|
||||
>({})
|
||||
|
||||
function hasBusyBrandTask() {
|
||||
return tasks.value.some(isBusyBrandTask)
|
||||
@@ -257,6 +262,7 @@ async function pollOnce() {
|
||||
current: Number(lp.info.current_line) || 0,
|
||||
total: Number(lp.info.total_lines) || 0,
|
||||
phase: lp.info.phase,
|
||||
text: (lp.info.progress_text || '').trim(),
|
||||
}
|
||||
} else {
|
||||
delete lineProgressMap.value[String(id)]
|
||||
@@ -367,9 +373,16 @@ function toBrandTaskView(item: BrandTaskItem): TaskItemView {
|
||||
const lp = isRunning(item) ? lineProgressMap.value[String(item.id)] : undefined
|
||||
const lineTotal = lp?.total || 0
|
||||
const lineCurrent = lp?.current || 0
|
||||
// 排队期显示执行方给的人话文案(已等待多少秒 / 同机几个槽在用):3700 之前排队期
|
||||
// 只有「排队中 / 已处理 0 行」,用户无法分辨是在排队还是卡死。
|
||||
const queueText = lp?.phase === 'queued' ? (lp.text || '').trim() : ''
|
||||
const extraLines = [
|
||||
...(item.file_paths?.length ? [`文件:${item.file_paths.length} 个`] : []),
|
||||
...(lp && lineTotal > 0 ? [`已处理 ${lineCurrent} 行 / 共 ${lineTotal} 行(含查询失败)`] : []),
|
||||
...(queueText
|
||||
? [queueText]
|
||||
: lp && lineTotal > 0
|
||||
? [`已处理 ${lineCurrent} 行 / 共 ${lineTotal} 行(含查询失败)`]
|
||||
: []),
|
||||
...(errorMessage(item) ? [`错误:${userNotice(errorMessage(item))}`] : []),
|
||||
]
|
||||
// 行级进度优先:完成数 = 已处理品牌行(成功或查询失败都计入),进度 = 完成数 / 总数 * 100
|
||||
@@ -379,7 +392,8 @@ function toBrandTaskView(item: BrandTaskItem): TaskItemView {
|
||||
progress = {
|
||||
percent: Math.max(0, Math.min(100, Math.round((lineCurrent / lineTotal) * 100))),
|
||||
stage: brandPhaseText(lp.phase),
|
||||
countLabel: `${lineCurrent}/${lineTotal}`,
|
||||
// 排队期不摆「0/265」:完成数恒为 0,具体等待情况在 extraLines 的排队文案里。
|
||||
countLabel: queueText ? undefined : `${lineCurrent}/${lineTotal}`,
|
||||
}
|
||||
} else {
|
||||
progress = {
|
||||
@@ -482,6 +496,33 @@ async function cancelTask(item: BrandTaskItem) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 失败/已取消的任务可以重新提交(沿用原单文件与通道,由本机客户端再跑一单)。 */
|
||||
function canResubmit(item: BrandTaskItem) {
|
||||
const status = String(item.status || '').toLowerCase()
|
||||
return status === 'failed' || status === 'cancelled'
|
||||
}
|
||||
|
||||
async function resubmitTask(item: BrandTaskItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认重新提交任务 ${item.id}?将沿用原文件的检测策略与采集方式,新建一单重新执行。`,
|
||||
'重新提交',
|
||||
{ type: 'warning' },
|
||||
)
|
||||
const res = await resubmitBrandTask(item.id, getPywebviewApi() ?? undefined)
|
||||
if (!res.available) {
|
||||
ElMessage.warning('当前客户端版本不支持重新提交,请升级客户端后重试')
|
||||
return
|
||||
}
|
||||
if (!res.success) throw new Error(res.error || '重新提交失败')
|
||||
ElMessage.success(res.taskId ? `已重新提交,新任务 ${res.taskId}` : '已重新提交')
|
||||
await syncTasksAndResumePolling()
|
||||
} catch (error) {
|
||||
if (error === 'cancel' || error === 'close') return
|
||||
ElMessage.error(error instanceof Error ? error.message : '重新提交失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTask(item: BrandTaskItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除任务 ${item.id}?删除后不可恢复。`, '删除任务', { type: 'warning' })
|
||||
|
||||
@@ -54,8 +54,13 @@ export interface BrandLineProgressInfo {
|
||||
current_line?: number
|
||||
/** 任务级品牌总数 */
|
||||
total_lines?: number
|
||||
/** crawling / assembling / uploading / failed */
|
||||
/** crawling / assembling / uploading / failed(排队期另有 queued) */
|
||||
phase?: string
|
||||
/**
|
||||
* 执行方每 15 秒心跳带上的人话文案,例如
|
||||
* 「排队等待执行(已等待 1234 秒;同机 3/4 个执行槽在用)」。
|
||||
*/
|
||||
progress_text?: string
|
||||
}
|
||||
|
||||
export interface BrandLineProgress {
|
||||
@@ -116,6 +121,12 @@ export interface BrandLocalBridge {
|
||||
task_id?: number
|
||||
error?: string
|
||||
}>
|
||||
/** 失败任务重跑(2026-11-23):文件/策略/通道沿用原单,由客户端再建一单并执行。 */
|
||||
resubmit_brand_task?: (payload: { taskId: number; uid: number }) => Promise<{
|
||||
success?: boolean
|
||||
task_id?: number
|
||||
error?: string
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,6 +157,26 @@ export function runBrandLocal(files: UploadedFileRef[], strategy: string, bridge
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新提交一个失败/已取消的品牌任务(3700 复盘:失败后界面没有任何重跑入口)。
|
||||
*
|
||||
* 走桥而不走相对地址:重跑必须由本机客户端建单并执行,线上 15126 无从替用户重跑;
|
||||
* 老客户端没有该方法 ⇒ available=false,页面提示升级客户端。
|
||||
*/
|
||||
export function resubmitBrandTask(taskId: string | number, bridge?: BrandLocalBridge) {
|
||||
if (!bridge?.resubmit_brand_task) {
|
||||
return Promise.resolve({ available: false as const })
|
||||
}
|
||||
return Promise.resolve(
|
||||
bridge.resubmit_brand_task({ taskId: Number(taskId), uid: getCurrentUserId() }),
|
||||
).then((res) => ({
|
||||
available: true as const,
|
||||
success: Boolean(res?.success),
|
||||
taskId: Number(res?.task_id) || 0,
|
||||
error: res?.error ? String(res.error) : '',
|
||||
}))
|
||||
}
|
||||
|
||||
export function createBrandTask(files: UploadedFileRef[], strategy: string) {
|
||||
return requestPostJson<BrandTaskMutationResponse>(
|
||||
`${API_PREFIX}/api/brand/tasks?userId=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
|
||||
@@ -222,13 +222,14 @@ export interface PywebviewApi {
|
||||
error?: string;
|
||||
}>;
|
||||
/**
|
||||
* 京东采集建单页「登录京麦」(2026-11-20):起本机京东采集专用浏览器、停在京麦
|
||||
* 登录页等人工登录(执行体在客户端 amazon/jd/login_window.py,登录态常驻采集专用
|
||||
* profile chrome_data_jd,登一次后续任务复用)。code 分档:成功 logged_in /
|
||||
* already_logged_in(带 message);失败 jd_busy(京东任务在跑)/ jd_login_running
|
||||
* (登录窗口已在等待,可恢复)/ window_closed(用户关了窗口,再点一次)/
|
||||
* timeout(等待超时,窗口保持打开)/ jd_page(真失败)。
|
||||
* 老客户端没有这个方法 ⇒ 页面把「登录京麦」按钮置灰并提示升级。
|
||||
* 京麦登录窗自动触发链路(2026-11-23「登录京麦」按钮退役,原 2026-11-20 独立登录
|
||||
* 入口):起本机京东采集专用浏览器、停在京麦登录页等人工登录(执行体在客户端
|
||||
* amazon/jd/login_window.py,登录态常驻采集专用 profile chrome_data_jd,登一次后续
|
||||
* 任务复用)。code 分档:成功 logged_in / already_logged_in(带 message);失败
|
||||
* jd_busy(京东任务在跑)/ jd_login_running(登录窗口已在等待,可恢复)/ window_closed
|
||||
* (用户关了窗口,下次动作会自动再弹)/ timeout(等待超时,窗口保持打开)/ jd_page(真失败)。
|
||||
* 调用方=shared/stores/jd-login-autoflow(同步分类 jd_login、任务致命公告、建单/重试
|
||||
* 预检三路自动触发)。老客户端没有这个方法 ⇒ 自动链路静默跳过并提示升级。
|
||||
*/
|
||||
open_jd_login?: () => Promise<{
|
||||
success: boolean;
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { resubmitBrandTask, type BrandLocalBridge } from '../src/shared/api/types/modules/brand.ts'
|
||||
|
||||
function setupWindow() {
|
||||
;(globalThis as Record<string, unknown>).window = {
|
||||
localStorage: { getItem: () => '42' },
|
||||
location: { origin: 'http://localhost' },
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 品牌任务「重新提交」(2026-11-23 任务 3700)。
|
||||
*
|
||||
* <p>3700 排队 120 分钟被判失败后,界面没有任何重跑入口——用户只能重新选文件、重新上传。
|
||||
* 重跑必须由本机客户端建单并执行(线上 15126 无从替用户执行),所以走桥而不是相对地址;
|
||||
* 老客户端没有该方法时必须明确回 available=false,页面据此提示升级,而不是静默失败。
|
||||
*/
|
||||
test('test_brand_resubmit_without_bridge_reports_unavailable', async () => {
|
||||
setupWindow()
|
||||
assert.deepEqual(await resubmitBrandTask(3700), { available: false })
|
||||
assert.deepEqual(await resubmitBrandTask(3700, {} as BrandLocalBridge), { available: false },
|
||||
'桥在但没有 resubmit_brand_task(老客户端)同样要回答不可用')
|
||||
})
|
||||
|
||||
test('test_brand_resubmit_forwards_task_id_and_uid', async () => {
|
||||
setupWindow()
|
||||
const calls: unknown[] = []
|
||||
const bridge: BrandLocalBridge = {
|
||||
resubmit_brand_task: (payload) => {
|
||||
calls.push(payload)
|
||||
return Promise.resolve({ success: true, task_id: 3720 })
|
||||
},
|
||||
}
|
||||
|
||||
const result = await resubmitBrandTask(3700, bridge)
|
||||
|
||||
assert.equal(result.available, true)
|
||||
assert.equal(result.success, true)
|
||||
assert.equal(result.taskId, 3720)
|
||||
assert.deepEqual(calls, [{ taskId: 3700, uid: 42 }],
|
||||
'桥调用要带 uid:本机 Flask 建单要按用户归属,且要校验原单归属')
|
||||
})
|
||||
|
||||
test('test_brand_resubmit_bridge_failure_is_reported', async () => {
|
||||
setupWindow()
|
||||
const bridge: BrandLocalBridge = {
|
||||
resubmit_brand_task: () => Promise.resolve({ success: false, error: '只有失败或已取消的任务可以重新提交' }),
|
||||
}
|
||||
|
||||
const result = await resubmitBrandTask(3700, bridge)
|
||||
|
||||
assert.equal(result.available, true)
|
||||
assert.equal(result.success, false)
|
||||
assert.match(result.error, /只有失败或已取消/)
|
||||
})
|
||||
|
||||
test('test_brand_resubmit_entry_only_for_failed_or_cancelled', () => {
|
||||
const page = readFileSync(
|
||||
join(import.meta.dirname, '..', 'src', 'pages', 'brand', 'components', 'BrandBrandTab.vue'),
|
||||
'utf8',
|
||||
)
|
||||
assert.match(page, /canResubmit/, '历史任务卡必须有重新提交判定')
|
||||
assert.match(page, /status === 'failed' \|\| status === 'cancelled'/, '只对失败/已取消出按钮')
|
||||
assert.match(page, /resubmitBrandTask\(item\.id/, '按钮必须经桥重提,而不是重新上传文件')
|
||||
})
|
||||
@@ -109,7 +109,11 @@ const BASELINE = {
|
||||
// 「已提示任务代」localStorage 读/写各一支 try/catch。读不出一律按「没提示过」处理(return []),
|
||||
// 写不进去就放弃跨页面去重(return,本次挂载仍由内存 Set 挡住重复弹窗)——两支都没有把
|
||||
// 用户可见错误吞掉(弹窗本身不受影响,丢的只是可选优化),silent 一格没涨、perFile 无新增条目。
|
||||
blocks: 334,
|
||||
// 335 = 334 + 1(2026-11-23 品牌任务「重新提交」,任务 3700 复盘):BrandBrandTab.vue 的
|
||||
// resubmitTask 包住重新提交请求——失败 ElMessage.error 当场把服务端文案报给用户、
|
||||
// 成功 ElMessage.success 并刷新看板;确认框的取消走 `error === 'cancel'` 直接 return。
|
||||
// 非静默(块内有用户可见出口),silent 一格没涨、perFile 无新增条目,只进 blocks。
|
||||
blocks: 335,
|
||||
// 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
|
||||
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
|
||||
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
|
||||
|
||||
@@ -73,3 +73,19 @@ test('light 白名单与后端 VO 的进度三字段同名同形', () => {
|
||||
assert.ok(polling.includes(`${field}: item.${field} ?? null`), `task-progress-polling.ts 归一时丢了 ${field}`)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 2026-11-23 任务 3700:品牌单排队 120 分钟后判死,界面全程只有「排队中 / 已处理 0 行」。
|
||||
* 客户端心跳一直带着人话文案(progressText),后端 2026-11-23 起把它透出成 progress_text,
|
||||
* 任务卡必须把它显示出来——否则用户无法分辨「在排队」还是「卡死」。
|
||||
*/
|
||||
test('品牌任务卡必须显示后端透出的排队文案 progress_text', () => {
|
||||
const src = readFileSync(join(COMPONENTS, 'BrandBrandTab.vue'), 'utf8')
|
||||
assert.match(src, /progress_text/, 'BrandBrandTab 必须读取 line_progress.info.progress_text')
|
||||
assert.match(src, /phase === 'queued'/, '排队文案只在 queued 阶段替代行数行')
|
||||
const types = readFileSync(
|
||||
join(import.meta.dirname, '..', 'src', 'shared', 'api', 'types', 'modules', 'brand.ts'),
|
||||
'utf8',
|
||||
)
|
||||
assert.match(types, /progress_text\?: string/, 'BrandLineProgressInfo 必须声明 progress_text')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user