620 lines
39 KiB
TypeScript
620 lines
39 KiB
TypeScript
/**
|
||
* 调度中心(图2 节点 ④ plan_tasks → ⑪ 派发执行)
|
||
* 清单怎么算、队列怎么排、心跳谁断了:后端是权威,这一页只负责说人话 + 给按钮。
|
||
*/
|
||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||
import { useSearchParams } from 'react-router-dom'
|
||
import * as api from '../../api/client'
|
||
import { fmtAgo, fmtMoney, statusLabel } from '../../lib/format'
|
||
import { useAutoRefresh } from '../../hooks'
|
||
import { Select } from '../../components/forms'
|
||
import { PageHead, ActionGroup, Actions, Button, Check, Ctlbar, Divider, Count, ErrorText, ExtLink, Field, Info, Layout, LinkButton, MONO, MUTED, MUTED_MONO, NumberInput, PageStack, Panel, PanelHead, ProgressBar, Row, Spinner, Status, Table, Tag, TagGroup, Toolbar, Value, Clamp, useNarrowTable } from '../../components/ui'
|
||
import { refresh, useProjectStore } from '../../stores/project'
|
||
import { useSystemStore } from '../../stores/system'
|
||
import { notify } from '../../stores/notice'
|
||
import { Checkbox } from '../../components/ui'
|
||
import { IconApi, IconClock, IconClose, IconPlayCircle, IconRetry, IconSound } from '../../components/icons'
|
||
import { IconSend } from '../../components/icons/extra'
|
||
|
||
const QUEUE_STATUSES = ['planned', 'queued', 'running', 'retrying', 'succeeded', 'failed', 'cancelled', 'skipped']
|
||
const QUEUE_KINDS = ['generate_shot', 'voiceover', 'qc_shot', 'compose', 'import', 'asset']
|
||
/** 后端 /api/meta 挂了也要能筛:这份兜底只在 meta 缺席时出现 */
|
||
const FALLBACK_TASK_STATUSES = ['planned', 'queued', 'running', 'retrying', 'waiting_review', 'succeeded', 'failed', 'cancelled', 'skipped']
|
||
const ACTIVE_STATUSES = ['queued', 'running', 'retrying', 'planned']
|
||
/** 执行方式是平台内部实现细节,界面只说人话:任务现在怎么跑、什么时候能看到结果 */
|
||
const EXEC_LABEL: Record<string, string> = { inline: '平台内即时执行', celery: '后台任务队列' }
|
||
/** 清单动作:后端是三态 enqueue / skip / needs_attention,别把「阻塞」显示成「跳过」 */
|
||
const ACTION_LABELS: Record<string, string> = { enqueue: '待入队', skip: '跳过', needs_attention: '预检阻塞' }
|
||
const actionLabel = (a: string) => ACTION_LABELS[a] || a || '—'
|
||
|
||
/** 心跳年龄说成人话:「12 分钟」比「742 秒」更能判断该不该干预。 */
|
||
function fmtAge(sec?: number | null) {
|
||
if (sec === null || sec === undefined) return '从未心跳'
|
||
if (sec < 60) return `${sec} 秒`
|
||
const m = Math.round(sec / 60)
|
||
return m < 60 ? `${m} 分钟` : `${Math.floor(m / 60)} 小时 ${m % 60} 分`
|
||
}
|
||
|
||
type Switches = { force: boolean; allow_unready: boolean }
|
||
|
||
export default function Dispatch() {
|
||
const projectId = useProjectStore((s) => s.id)
|
||
const meta = useSystemStore((s) => s.meta)
|
||
const [params] = useSearchParams()
|
||
const [error, setError] = useState('')
|
||
const [busy, setBusy] = useState('')
|
||
const [plan, setPlan] = useState<any>(null)
|
||
const [queue, setQueue] = useState<any>(null)
|
||
const [tasks, setTasks] = useState<any[]>([])
|
||
/** 任务状态枚举只认后端 /api/meta(TaskStatus.ALL):状态机加一档,筛选就该跟着长,
|
||
* 不能再靠这里抄一遍 —— 抄漏的那档会在列表里出现却筛不出来。 */
|
||
const taskStatusOptions: string[] = (meta?.task_statuses as string[]) || FALLBACK_TASK_STATUSES
|
||
const [statusFilter, setStatusFilter] = useState('')
|
||
const [drain, setDrain] = useState(true)
|
||
const [shotIds, setShotIds] = useState<number[]>([])
|
||
const [withVoiceover, setWithVoiceover] = useState(true)
|
||
const [switches, setSwitches] = useState<Switches>({ force: false, allow_unready: false })
|
||
const [priority, setPriority] = useState(5)
|
||
const [limit, setLimit] = useState(32)
|
||
const [timeout_, setTimeout_] = useState(900)
|
||
|
||
const counts = queue?.counts || {}
|
||
const executorLabel = queue?.executor ? (EXEC_LABEL[queue.executor] || queue.executor) : '未知'
|
||
const activeCount = ACTIVE_STATUSES.reduce((sum, k) => sum + (counts[k] || 0), 0)
|
||
/** 心跳停更的「进行中」:执行体可能已经没了(服务被杀 / 平台热重载),界面必须说破。 */
|
||
const staleTasks = tasks.filter((t) => t.stale)
|
||
const livenessLabel = (() => {
|
||
const sec = Number(tasks.find((t) => t.stale)?.stale_after_seconds || 0)
|
||
return sec >= 60 ? `${Math.round(sec / 60)} 分钟` : `${sec} 秒`
|
||
})()
|
||
const enqueueable = (plan?.shots || []).filter((s: any) => s.action !== 'skip')
|
||
const voiceoverable = (plan?.voiceovers || []).filter((v: any) => v.action !== 'skip')
|
||
/* 镜头清单与配音清单合并成一张表(原来两段 tbody 首尾相接,看起来像一张表):
|
||
走 antd Table 就得有一个数据源,所以在这里合流,用 _row 区分两种行的取数。 */
|
||
const planRows: any[] = [
|
||
...(plan?.shots || []).map((r: any) => ({ ...r, _row: 'shot', _key: `s${r.shot_id}` })),
|
||
...(plan?.voiceovers || []).map((r: any) => ({ ...r, _row: 'voice', _key: `v${r.shot_id}` }))
|
||
]
|
||
/** 队列矩阵按 kind×status 反查,表格里三列循环不必每次都扫一遍数组 */
|
||
const matrix = useMemo(() => {
|
||
const map = new Map<string, any>()
|
||
for (const row of queue?.matrix || []) map.set(`${row.kind}|${row.status}`, row)
|
||
return map
|
||
}, [queue])
|
||
|
||
/** load 里要按「当前」的强制/放行开关问后端,但它们又不该进依赖数组
|
||
* (否则每勾一次就把整页三张表重新拉一遍),所以留一份 ref 给闭包用。 */
|
||
const switchesRef = useRef(switches)
|
||
switchesRef.current = switches
|
||
|
||
// 清单必须按当前这几个开关去问后端:后端算 skip/enqueue 看的正是 force/allow_unready。
|
||
// 以前固定不带 force 去读,已生成或已审核合格的镜头永远显示「跳过」,
|
||
// 加上下面 skip 行不许勾选,用户从分镜点「重新生成」过来就一个都选不动。
|
||
const load = useCallback(async (silent = true, sw?: Switches) => {
|
||
if (!projectId) return null
|
||
const gates = sw ?? switchesRef.current
|
||
if (!silent) setBusy('读取队列')
|
||
try {
|
||
const [pl, qu, tk] = await Promise.all([
|
||
api.get(`/api/projects/${projectId}/tasklist`, { force: gates.force, allow_unready: gates.allow_unready }),
|
||
api.get(`/api/projects/${projectId}/queue`),
|
||
api.get('/api/tasks', { project_id: projectId, status: statusFilter })
|
||
])
|
||
setPlan(pl.plan)
|
||
setQueue(qu)
|
||
setTasks(tk.tasks || [])
|
||
setError('')
|
||
return pl.plan
|
||
} catch (exc: any) { setError(exc?.message || String(exc)); return null }
|
||
finally { setBusy('') }
|
||
}, [projectId, statusFilter])
|
||
|
||
async function run(label: string, fn: () => Promise<any>, message?: (res: any) => string) {
|
||
setBusy(label); setError('')
|
||
try {
|
||
const res = await fn()
|
||
const text = message ? message(res) : ''
|
||
if (text) notify(text)
|
||
await Promise.all([load(), refresh()])
|
||
return res
|
||
} catch (exc: any) { setError(exc?.message || String(exc)); return null }
|
||
finally { setBusy('') }
|
||
}
|
||
|
||
/** 勾选「强制重建 / 放行未就绪」后清单要重算,否则「动作」列还是按旧开关显示跳过。
|
||
* 只监听这两个开关:load 的函数身份也随状态筛选变化,写进依赖会多发一次请求。 */
|
||
const booted = useRef(false)
|
||
useEffect(() => {
|
||
if (!booted.current) { booted.current = true; return }
|
||
void load()
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [switches.force, switches.allow_unready])
|
||
|
||
useEffect(() => {
|
||
let alive = true
|
||
;(async () => {
|
||
// 分镜工作台卡片上的「▷ 生成 / ↻ 重生成」带 ?shot= 过来时,预勾选该镜头,避免误伤整批。
|
||
// 带 force=1 说明来意就是**重做这一镜**:它的产物已经存在,后端默认判 skip,
|
||
// 不先把强制打开,这一镜在清单里根本选不动。
|
||
const want = Number(params.get('shot') || 0)
|
||
const wantForce = !!want && Number(params.get('force') || 0) === 1
|
||
if (wantForce) setSwitches((s) => ({ ...s, force: true }))
|
||
const pl = await load(false, { force: wantForce, allow_unready: false })
|
||
if (!alive) return
|
||
const row = (pl?.shots || []).find((s: any) => s.shot_id === want)
|
||
if (!row) return
|
||
setShotIds([want])
|
||
if (row.action === 'skip') {
|
||
notify(`镜头 #${row.order_index} 暂不需要生成:${row.reason}。勾上「强制重建任务」就能只重做它`)
|
||
} else {
|
||
notify(`已勾选镜头 #${row.order_index},点「入队所选」即可只生成这一镜`)
|
||
}
|
||
})()
|
||
return () => { alive = false }
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [projectId])
|
||
|
||
/* 队列里有活就 4 秒看一次;空闲时不必反复敲后端 */
|
||
useAutoRefresh(() => void load(), 4000, !!busy, false)
|
||
|
||
/** 派发/入队返回的 blocked[]:模型停用或并发·RPM 额度用尽时说明「为什么没动」 */
|
||
function blockedNote(r: any) {
|
||
const blocked = r?.dispatched?.blocked || []
|
||
return blocked.length ? `;${blocked.length} 个模型暂不可派发:`
|
||
+ blocked.map((b: any) => `${b.provider_model}(${b.reason})`).join(';') : ''
|
||
}
|
||
|
||
const enqueue = () => run('生成任务并入队', () => api.post(`/api/projects/${projectId}/tasks`, {
|
||
shot_ids: shotIds.length ? shotIds : null, force: switches.force, allow_unready: switches.allow_unready,
|
||
priority, with_voiceover: withVoiceover, actor: 'studio'
|
||
}), (r) => `已入队 ${r?.created?.count ?? 0} 个任务(其中配音 ${(r?.created?.voiceovers || []).length},`
|
||
+ `跳过 ${(r?.created?.skipped || []).length} —— 跳过原因见清单「动作」列` + blockedNote(r))
|
||
|
||
const buildVoiceover = () => run('生成配音任务', () => api.post(`/api/projects/${projectId}/voiceover`, {
|
||
shot_ids: null, only_missing: true, priority: 4
|
||
}), (r) => `已创建 ${r?.count ?? 0} 条配音任务`)
|
||
|
||
const doDispatch = () => run(drain ? '派发并排空队列' : '派发任务', () => api.post(`/api/projects/${projectId}/dispatch`, {
|
||
limit, drain, timeout: timeout_
|
||
}), (r) => drain
|
||
? `本轮派发 ${r?.dispatched?.count ?? 0} 个,排空期间跑完 `
|
||
+ `${r?.drained?.completed_during_drain ?? 0} 个(终态累计 ${r?.drained?.completed ?? 0})`
|
||
+ (r?.drained?.remaining ? `,仍在队列 ${r.drained.remaining} 个` : ',队列已清空')
|
||
+ (r?.drained?.timed_out ? '(等待超时,可加大「排空等待」或再点一次)' : '')
|
||
+ (r?.drained?.stalled
|
||
? `;已停滞:${(r.drained.stalled_detail?.blocked || []).map((b: any) => `${b.provider_model} ${b.reason}`).join(';')}`
|
||
: '')
|
||
+ blockedNote(r)
|
||
: `已派发 ${r?.dispatched?.count ?? 0} 个任务${blockedNote(r)}`)
|
||
|
||
const retryFailed = () => run('重排失败任务', () => api.post(`/api/projects/${projectId}/tasks/retry-failed`, { reset_attempts: true }), (r) => `重新入队 ${r?.count ?? 0} 个失败任务`)
|
||
const cancelActive = () => run('取消进行中的任务', () => api.post(`/api/projects/${projectId}/tasks/cancel-active`, { reason: '人工在调度中心取消' }), (r) => `已取消 ${r?.count ?? 0} 个任务`)
|
||
const resume = () => run('断点续跑', () => api.post(`/api/projects/${projectId}/resume`, {}), (r) => `恢复中断任务 ${r?.resume?.count ?? 0} 个,本进程已接手 ${(r?.recovered_here || []).length} 个`)
|
||
|
||
const retryTask = (t: any) => run('重试任务', () => api.post(`/api/tasks/${t.id}/retry`, {}), () => `任务 #${t.id} 已重新入队`)
|
||
const cancelTask = (t: any) => run('取消任务', () => api.post(`/api/tasks/${t.id}/cancel`, { reason: '人工取消' }), () => `任务 #${t.id} 已取消`)
|
||
|
||
function toggleShot(id: number) {
|
||
setShotIds((list) => (list.includes(id) ? list.filter((x) => x !== id) : [...list, id]))
|
||
}
|
||
|
||
/* 表格窄档(<992):两张表各备一套列,宽档那份列定义一字不动(1440 像素级不变) */
|
||
const narrow = useNarrowTable()
|
||
|
||
return (
|
||
<PageStack>
|
||
{/* 页头(第 1 条):入队是这一页唯一整页成立的主操作,从「分镜任务清单」的卡头里提出来。
|
||
卡头只留「预计成本 · 共 N 行」这句清单自身的口径。 */}
|
||
<PageHead
|
||
title="任务调度中心"
|
||
sub="按分镜清单入队生成与配音任务,跟踪队列、重试与并发;模型本身的配置在模型管理中心。"
|
||
actions={<Button type="primary" disabled={!!busy} onClick={enqueue} icon={<IconPlayCircle />}>入队所选 / 全部待生成</Button>}
|
||
/>
|
||
|
||
{/* 队列总览:一排 Tag 悬浮在页面底色上时,它和下面的卡片没有任何归属关系
|
||
(截图上就是「这行字是页面上的脏东西」)。它是一块只有卡头的卡 = <Toolbar>。
|
||
只读计数仍走 Tag,不借 Chip 的胶囊皮肤(规范 §2.0)。 */}
|
||
<Toolbar
|
||
info={<TagGroup className="mb-0">
|
||
<Tag tone="info">任务执行:{executorLabel}</Tag>
|
||
{Object.entries(counts).map(([k, v]) => <Tag key={k}>{statusLabel(k)} {String(v)}</Tag>)}
|
||
{!activeCount && <span className={MUTED}>队列空闲</span>}
|
||
</TagGroup>}
|
||
actions={busy ? <Value><Spinner /> {busy}…</Value> : undefined} />
|
||
<ErrorText>{error}</ErrorText>
|
||
|
||
{/* ===== 任务清单(图2 节点④ plan_tasks) ===== */}
|
||
<Layout>
|
||
<Panel>
|
||
<PanelHead title="分镜任务清单"
|
||
sub={<>预计成本 {fmtMoney(plan?.estimated_cost, plan?.currency)} · 共 {planRows.length} 行</>} />
|
||
{/* 八颗只读计数原先是无底纹的灰胶囊:统计块没有底纹就没有「块」的边界,
|
||
在 378px 侧栏里还折成 7+1 的孤尾行。改成回显表:标签列由 antd 上 colorFillAlter
|
||
底纹,对账单式对齐;数值等宽、只有非零才上色,0 降成次要色不占注意力。
|
||
列数跟着屏宽走(窄屏 2 列、桌面 4 列):写死 column={2} 时八颗计数要排四行,
|
||
这块回显比下面的任务清单还高,主客颠倒。 */}
|
||
<Info className="mb-3" column={{ xs: 2, md: 3, lg: 4 }} items={[
|
||
{ label: '待入队', value: <Count n={enqueueable.length} /> },
|
||
{ label: '已排队', value: <Count n={plan?.queued_count || 0} /> },
|
||
{ label: '待配音', value: <Count n={voiceoverable.length} /> },
|
||
{ label: '预计配音', value: <Count n={plan?.voiceover_count || 0} unit="条" /> },
|
||
{ label: '预检就绪', value: <Count n={plan?.preflight?.ready || 0} tone="ok" /> },
|
||
{ label: '预检告警', value: <Count n={plan?.preflight?.warnings || 0} tone="warn" /> },
|
||
{ label: '阻塞', value: <Count n={plan?.blocked_count || 0} tone="bad" /> },
|
||
{ label: '跳过', value: <Count n={plan?.skipped_count || 0} /> },
|
||
]} />
|
||
<Table
|
||
maxHeight={360}
|
||
/* 行高纪律(第 27 轮全站表格体检):这张表原先定宽 748 + minWidth 860,
|
||
说明列只分到 112px,一句「画面产物已存在(…mp4),镜头状态 generated」折成 8 行,
|
||
行高 168px —— 一屏只看得下两行清单。
|
||
做法:时长并进镜头列第二行(Provider 也挂在那儿),说明拿剩下的 274px 并封顶两行;
|
||
定宽合计 400 < 容器 674,横向滚动同时归零。 */
|
||
minWidth={false}
|
||
rowKey="_key"
|
||
dataSource={planRows}
|
||
empty="还没有分镜清单,先去「分镜工作台」拆镜头。"
|
||
columns={narrow ? [
|
||
|
||
/* ── 窄档(<992 · NEX 阶段 8.5 六表收口之②「分镜任务清单」)──────────────────
|
||
数据特点:一行 = 一个镜头要不要入队,读的人是「为什么这镜被跳过」。
|
||
宽档定宽合计 40+200+84+76 = 400,430 视口容器实测 356 ⇒ 溢出 44,
|
||
说明列被挤到 0 宽(tableaudit 读到 说明=0),恰恰是唯一不能丢的那一列。
|
||
方案:不砍列、不横滚,把「动作」标签与「预估成本」并进镜头行的第二行
|
||
(两者都只有几十字像素宽),时长/Provider 那行元信息退到第三行,
|
||
说明列回到 140–306px 并保留两行封顶 + 全文 title。
|
||
三行预算:正文 22 + 标签 22 + 元信息 20 + 单元格内边距 16 = 80 ≤ 84。 */
|
||
{ title: '#', key: 'pick', width: 40, align: 'center', render: (_: any, row: any) => (
|
||
row._row === 'shot'
|
||
? <Checkbox className="mx-auto" aria-label={`选择镜头 ${row.order_index}`}
|
||
checked={shotIds.includes(row.shot_id)}
|
||
disabled={row.action === 'skip' && !switches.force}
|
||
onCheckedChange={() => toggleShot(row.shot_id)} />
|
||
: <IconSound />
|
||
) },
|
||
{ title: '镜头 / 动作', key: 'shot', width: 176, render: (_: any, row: any) => {
|
||
const who = row._row === 'shot' ? row.title : '配音'
|
||
const meta = row._row === 'shot'
|
||
? `shot#${row.shot_id} · ${row.duration}s · ${row.provider || '—'}/${row.model || '默认'}`
|
||
: `shot#${row.shot_id} · ${row.chars} 字 · TTS`
|
||
const isShot = row._row === 'shot'
|
||
const tone = isShot
|
||
? (row.action === 'enqueue' ? 'info' : row.action === 'needs_attention' ? 'bad' : 'warn')
|
||
: (row.action !== 'skip' ? 'info' : 'default')
|
||
const act = isShot ? actionLabel(row.action) : (row.action !== 'skip' ? '待配音' : '跳过')
|
||
return <>
|
||
<Clamp lines={1} title={`#${row.order_index} ${who}`}><b>#{row.order_index}</b> {who}</Clamp>
|
||
{/* nowrap + 标签自带的 max-width/ellipsis:窄到放不下时折的是标签正文,
|
||
不是把整行撑出第三排(R17 那条 84px 的行高红线) */}
|
||
<div className="mt-0.5 flex min-w-0 flex-nowrap items-center gap-1">
|
||
<Tag size="sm" tone={tone}>{act}</Tag>
|
||
<span className={MONO}>{isShot ? fmtMoney(row.estimated_cost) : '—'}</span>
|
||
</div>
|
||
<Clamp lines={1} className={MUTED_MONO} title={meta}>{meta}</Clamp>
|
||
</>
|
||
} },
|
||
{ title: '说明', key: 'reason', className: MUTED, render: (_: any, row: any) => {
|
||
const blocking = row.blocking?.length ? `阻塞:${row.blocking.join(';')}` : ''
|
||
return <Clamp title={[row.reason, blocking].filter(Boolean).join(' ')}>
|
||
{row.reason}
|
||
{blocking ? <span className="text-error"> {blocking}</span> : null}
|
||
</Clamp>
|
||
} }
|
||
|
||
] : [
|
||
{ title: '#', key: 'pick', width: 40, align: 'center', render: (_: any, row: any) => (
|
||
row._row === 'shot'
|
||
? <Checkbox className="mx-auto" aria-label={`选择镜头 ${row.order_index}`}
|
||
checked={shotIds.includes(row.shot_id)}
|
||
disabled={row.action === 'skip' && !switches.force}
|
||
onCheckedChange={() => toggleShot(row.shot_id)} />
|
||
: <IconSound />
|
||
) },
|
||
{ title: '镜头', key: 'shot', width: 200, render: (_: any, row: any) => {
|
||
const who = row._row === 'shot' ? row.title : '配音'
|
||
const meta = row._row === 'shot'
|
||
? `shot#${row.shot_id} · ${row.duration}s · ${row.provider || '—'}/${row.model || '默认'}`
|
||
: `shot#${row.shot_id} · ${row.chars} 字 · TTS`
|
||
return <>
|
||
<Clamp lines={1} title={`#${row.order_index} ${who}`}><b>#{row.order_index}</b> {who}</Clamp>
|
||
<Clamp lines={1} className={MUTED_MONO} title={meta}>{meta}</Clamp>
|
||
</>
|
||
} },
|
||
{ title: '动作', key: 'action', width: 84, render: (_: any, row: any) => (
|
||
row._row === 'shot'
|
||
? <Tag tone={row.action === 'enqueue' ? 'info' : row.action === 'needs_attention' ? 'bad' : 'warn'}>{actionLabel(row.action)}</Tag>
|
||
: <Tag tone={row.action !== 'skip' ? 'info' : 'default'}>{row.action !== 'skip' ? '待配音' : '跳过'}</Tag>
|
||
) },
|
||
{ title: '预估成本', key: 'cost', width: 76, align: 'right', className: MONO,
|
||
render: (_: any, row: any) => (row._row === 'shot' ? fmtMoney(row.estimated_cost) : '—') },
|
||
{ title: '说明', key: 'reason', className: MUTED, render: (_: any, row: any) => {
|
||
const blocking = row.blocking?.length ? `阻塞:${row.blocking.join(';')}` : ''
|
||
return <Clamp title={[row.reason, blocking].filter(Boolean).join(' ')}>
|
||
{row.reason}
|
||
{blocking ? <span className="text-error"> {blocking}</span> : null}
|
||
</Clamp>
|
||
} }
|
||
]}
|
||
/>
|
||
</Panel>
|
||
|
||
<Panel>
|
||
<PanelHead title="调度控制" />
|
||
<Ctlbar>
|
||
{/* 三条开关是一个决定(这批任务怎么排),右侧窄栏 378px 里横排必拆,
|
||
竖排等宽;「优先级」是另一个字段,留在开关组外面 */}
|
||
<ActionGroup stack className="w-full">
|
||
<Check checked={withVoiceover} onChange={setWithVoiceover}>入队时一并排配音任务</Check>
|
||
<Check checked={switches.allow_unready} onChange={(v) => setSwitches((s) => ({ ...s, allow_unready: v }))}>放行预检未通过的镜头(默认只跳过它们)</Check>
|
||
<Check title="忽略「产物已存在 / 已审核合格 / 已在队列」这三类跳过判定,也忽略幂等键。要单独重做某一镜就得勾它"
|
||
checked={switches.force} onChange={(v) => setSwitches((s) => ({ ...s, force: v }))}>强制重建任务(忽略幂等,可重做已生成的镜头)</Check>
|
||
</ActionGroup>
|
||
<Field inline label="优先级" width="narrow">
|
||
<NumberInput min={0} max={9} aria-label="任务优先级" value={priority} onChange={ (v) => setPriority(v)} />
|
||
</Field>
|
||
</Ctlbar>
|
||
<Divider />
|
||
<Ctlbar>
|
||
<Check title="勾选「派发后同步排空」会一直等到任务执行结束再返回,适合小批量验证;不勾选时任务留在队列后台执行,页面自动刷新进度。"
|
||
checked={drain} onChange={setDrain}>派发后同步排空(等任务跑完再返回)</Check>
|
||
<Field inline label="单次派发上限" width="narrow">
|
||
<NumberInput min={1} max={256} aria-label="单次派发上限" value={limit} onChange={ (v) => setLimit(v)} />
|
||
</Field>
|
||
<Field inline label="排空等待(秒)" width="narrow">
|
||
<NumberInput min={30} max={7200} aria-label="排空等待秒数" value={timeout_} onChange={ (v) => setTimeout_(v)} />
|
||
</Field>
|
||
</Ctlbar>
|
||
<Actions>
|
||
<Button type="primary" disabled={!!busy} onClick={doDispatch}
|
||
icon={<IconSend />}>{drain ? '派发并排空队列' : '只派发'}</Button>
|
||
<Button disabled={!!busy} onClick={buildVoiceover}
|
||
icon={<IconSound />}>批量生成配音</Button>
|
||
</Actions>
|
||
<Divider text="异常处理" />
|
||
{/* 三颗都是「异常处理」,合计 480px > 侧栏卡 378px:竖排等宽,
|
||
不留「前两颗并排、第三颗孤零零一行」那种 ragged 折行 */}
|
||
<Actions>
|
||
<ActionGroup stack className="w-full">
|
||
<Button disabled={!!busy} onClick={retryFailed}
|
||
icon={<IconRetry />}>重排全部失败任务</Button>
|
||
<Button disabled={!!busy} onClick={resume}
|
||
icon={<IconClock />}>断点续跑(恢复中断)</Button>
|
||
<Button disabled={!!busy} onClick={cancelActive}
|
||
icon={<IconClose />}>取消进行中任务</Button>
|
||
</ActionGroup>
|
||
</Actions>
|
||
</Panel>
|
||
</Layout>
|
||
|
||
{/* ===== 队列与容量 ===== */}
|
||
<Layout>
|
||
<Panel>
|
||
<PanelHead title="队列状态" />
|
||
<Table
|
||
maxHeight={false}
|
||
/* 任务类型列 5 个字(「时间线合成」)压到 104 就折行,八颗计数列不给宽度:
|
||
104 + 8×71 = 672 ≈ 容器 674,minWidth 从 760 撤掉,横滚归零。 */
|
||
minWidth={false}
|
||
rowKey={(kind: string) => kind}
|
||
dataSource={QUEUE_KINDS}
|
||
columns={[
|
||
{ title: '任务类型', key: 'kind', width: 104, render: (_: any, kind: any) => <b>{statusLabel(kind)}</b> },
|
||
...QUEUE_STATUSES.map((st) => ({
|
||
title: statusLabel(st), key: st, align: 'center' as const,
|
||
render: (_: any, kind: string) => {
|
||
const hit = matrix.get(`${kind}|${st}`)
|
||
return hit ? <Tag>{hit.count || ''}</Tag> : null
|
||
}
|
||
}))
|
||
]}
|
||
/>
|
||
</Panel>
|
||
|
||
<Panel>
|
||
<PanelHead title="模型并发与限流" />
|
||
<Table
|
||
maxHeight={false}
|
||
/* 这张表住在 9/24 的侧栏里(容器 378):六列 + minWidth=700 等于
|
||
在窄栏里横滚一条 700px 的带子,槽位 / RPM / 状态三列各只露半个字。
|
||
收成三列:名称自己折,并发与额度各一颗数字,状态标签跟着名称走 —— 横滚归零。 */
|
||
minWidth={false}
|
||
rowKey={(c: any) => `${c.provider}${c.model}${c.media_type}`}
|
||
dataSource={queue?.capacity || []}
|
||
empty="没有登记并发的模型:所有任务按默认额度执行。"
|
||
columns={[
|
||
{ title: 'Provider / 模型', key: 'model', render: (_: any, c: any) => (
|
||
<>
|
||
<Clamp lines={1} className={MONO} title={`${c.provider} / ${c.model || '默认'}`}>
|
||
{c.provider} / {c.model || '默认'}
|
||
</Clamp>
|
||
<span className="inline-flex items-center gap-1">
|
||
<Tag size="sm" tone={!c.enabled ? 'bad' : c.saturated ? 'warn' : 'ok'}>
|
||
{!c.enabled ? '已停用' : c.saturated ? '满载' : '可用'}
|
||
</Tag>
|
||
<span className={MUTED}>{c.media_type}</span>
|
||
</span>
|
||
</>
|
||
) },
|
||
{ title: '运行 / 排队', key: 'running', width: 88, align: 'center', className: MONO,
|
||
render: (_: any, c: any) => `${c.running} / ${c.queued}` },
|
||
{ title: '槽位 / RPM', key: 'slots', width: 92, align: 'center',
|
||
render: (_: any, c: any) => (
|
||
<>
|
||
<div className={MONO}>{c.slots}/{c.concurrency_limit}</div>
|
||
<div className={MUTED_MONO}>RPM {c.rpm_headroom}</div>
|
||
</>
|
||
) }
|
||
]}
|
||
/>
|
||
</Panel>
|
||
</Layout>
|
||
|
||
{/* ===== 任务列表 ===== */}
|
||
<Panel>
|
||
<PanelHead
|
||
title={<>任务执行明细({tasks.length})
|
||
{staleTasks.length ? <Tag tone="warn" className="ml-2">{staleTasks.length} 条心跳已停止</Tag> : null}
|
||
</>}
|
||
sub={staleTasks.length
|
||
? <>这些任务的执行体超过 {livenessLabel}没有报活:多半是那台机器上的模型服务或平台进程中断过。
|
||
产物与断点都留着,平台回收后会自动续跑;着急就点上方「断点续跑」立即处理。</>
|
||
: undefined}
|
||
right={<Ctlbar as="div" className="mb-0">
|
||
<Field inline label="状态" width="narrow">
|
||
<Select ariaLabel="任务状态筛选" value={statusFilter} onChange={setStatusFilter}
|
||
options={[{ value: '', label: '全部状态' }, ...taskStatusOptions.map((s) => ({ value: s, label: statusLabel(s) }))]} />
|
||
</Field>
|
||
</Ctlbar>} />
|
||
<Table
|
||
/* 行高纪律(第 27 轮体检:定宽合计 1152 + 错误列 348,最高行仍 125px,横滚 1500):
|
||
ID 并进取名行、心跳停服从三行红字换成一颗图标标签(解释留在 title 和卡头 sub),
|
||
长文案一律 <Clamp> 封顶两行;定宽降到 896,容器 1118 剩下的 222px 全给错误列
|
||
——「长文列 ≥ 200px」达标,横向滚动同时归零。 */
|
||
minWidth={false}
|
||
dataSource={tasks}
|
||
empty="暂无任务,先在上方生成任务清单并入队。"
|
||
columns={narrow ? [
|
||
|
||
/* ── 窄档(<992 · NEX 阶段 8.5 六表收口之③「任务执行明细」)──────────────────
|
||
数据特点:61 行的执行流水,要扫的是「哪条挂了 / 挂在哪 / 能不能重试」。
|
||
宽档九列定宽 902,430 容器 356 ⇒ 溢出 546,错误列 0 宽把整行撑到 103px;
|
||
768 那档(容器 462)同样溢出 400。九列不可能挤进一条手机屏。
|
||
方案:列数 9 → 3,次要列**并进主列**而不是隐藏——
|
||
· 任务列吃下 类型/阶段/镜头/进度/尝试/耗时(第三行等宽小字,全文挂 title)
|
||
· 状态列吃下 心跳标签与相对时间,和「错误 / 检查点」同格:
|
||
报错本来就是状态的下文,窄屏并成一段反而少一次横向找列
|
||
· 后端与 worker 只留在 title 里:它是排障时复制用的,不是扫读用的
|
||
行高:正文 22 + 状态 22 + 元信息 20 + 内边距 16 = 80 ≤ 84;
|
||
操作列在窄档回到 80px(重试 / 取消互斥,永远只有一颗 sm 按钮)。 */
|
||
{ title: '任务', key: 'name', width: 148, render: (_: any, t: any) => {
|
||
const el = t.elapsed_ms ? `${(t.elapsed_ms / 1000).toFixed(1)}s`
|
||
: t.queue_wait_ms ? `排队 ${(t.queue_wait_ms / 1000).toFixed(1)}s` : '—'
|
||
/* 阶段 8.5 第 3 项数据完整性回归补的一刀:宽档「任务」列第二行是
|
||
`配音 · voiceover`(类型中文名 + stage 码),窄档原本整行丢了它——
|
||
不是折行折掉的,是这一档压根没有这两个字段(430 实测 missing:
|
||
voiceover / asset / compose / dispatch / quality_check /
|
||
时间线合成 / 资产处理)。
|
||
放在**句尾**而不是句首:这一格正文 132px、line-clamp 1,实测正文要 3 行
|
||
(sh=60 / ch=20),句首句尾同样是「只有开头十几个字符看得见」,
|
||
摆句首等于把 100% 这个数字换成 stage 码——状态标签(第二行)加错误列
|
||
已经把「哪条挂了」答完,窄屏要扫的那一位是进度与尝试次数。
|
||
两个字段仍然实打实在这格里:能朗读、能选中复制、悬停读全(§13.2.1)。 */
|
||
const meta = `进度 ${Math.round((t.progress || 0) * 100)}% · 尝试 ${t.attempts}/${t.max_attempts} · ${el}`
|
||
+ ` · ${t.shot_id ? `镜头#${t.shot_id}` : t.timeline_id ? `时间线#${t.timeline_id}` : '—'}`
|
||
+ ` · ${statusLabel(t.kind)} · ${t.stage}`
|
||
return <>
|
||
<Clamp lines={1} title={`#${t.id} ${t.name}`}><span className={MONO}>#{t.id}</span> {t.name}</Clamp>
|
||
<div className="mt-0.5 flex min-w-0 flex-nowrap items-center gap-1">
|
||
<Status value={t.status} />
|
||
{t.stale
|
||
? <Tag size="sm" tone="warn"
|
||
title={`执行体超过 ${fmtAge(t.heartbeat_age_seconds)}没有报活:产物与断点都留着,平台回收后会自动续跑`}>
|
||
心跳停止
|
||
</Tag>
|
||
: <span className={MUTED}>{fmtAgo(t.updated_at)}</span>}
|
||
</div>
|
||
<Clamp lines={1} className={MUTED_MONO}
|
||
title={`${meta} · ${statusLabel(t.execution_backend)} ${t.worker_id || ''}`}>
|
||
{meta}
|
||
</Clamp>
|
||
</>
|
||
} },
|
||
{ title: '状态 / 错误 / 检查点', key: 'error', render: (_: any, t: any) => {
|
||
const detail = [
|
||
t.error_message ? `${t.error_code || 'error'} ${t.error_message}` : '',
|
||
t.checkpoint?.last_note || ''
|
||
].filter(Boolean).join(' / ')
|
||
return <>
|
||
<Clamp title={detail}>
|
||
{t.error_message ? <span className="text-error">{t.error_code} {t.error_message}</span> : null}
|
||
{t.checkpoint?.last_note ? <span> {t.checkpoint.last_note}</span>
|
||
: Object.keys(t.checkpoint || {}).length
|
||
? <span className={MUTED_MONO}> checkpoint: {JSON.stringify(t.checkpoint)}</span> : null}
|
||
</Clamp>
|
||
{t.output_url ? <ExtLink href={t.output_url}>产物</ExtLink> : null}
|
||
</>
|
||
} },
|
||
{ title: '操作', key: 'actions', width: 80, align: 'right', render: (_: any, t: any) => (
|
||
<Row tight className="justify-end">
|
||
{['failed', 'cancelled'].includes(t.status)
|
||
? <Button icon={<IconRetry />} size="sm" onClick={() => retryTask(t)}>重试</Button> : null}
|
||
{ACTIVE_STATUSES.includes(t.status)
|
||
? <Button icon={<IconClose />} size="sm" onClick={() => cancelTask(t)}>取消</Button> : null}
|
||
{t.status === 'succeeded' || t.status === 'skipped' ? <span className={MUTED}>—</span> : null}
|
||
</Row>
|
||
) }
|
||
|
||
] : [
|
||
{ title: '任务', key: 'name', width: 180, render: (_: any, t: any) => (
|
||
<>
|
||
<Clamp lines={1} title={`#${t.id} ${t.name}`}><span className={MONO}>#{t.id}</span> {t.name}</Clamp>
|
||
<Clamp lines={1} className={MUTED_MONO} title={`${statusLabel(t.kind)} · ${t.stage}`}>
|
||
{statusLabel(t.kind)} · {t.stage}
|
||
</Clamp>
|
||
</>
|
||
) },
|
||
{ title: '镜头', key: 'shot', width: 78, className: MONO,
|
||
render: (_: any, t: any) => (t.shot_id ? `#${t.shot_id}` : t.timeline_id ? `时间线#${t.timeline_id}` : '—') },
|
||
{ title: '后端', key: 'backend', width: 124, render: (_: any, t: any) => (
|
||
<>
|
||
<Clamp lines={1} className={MUTED} title={statusLabel(t.execution_backend)}>{statusLabel(t.execution_backend)}</Clamp>
|
||
<Clamp lines={1} className={MUTED_MONO} title={t.worker_id}>{t.worker_id}</Clamp>
|
||
</>
|
||
) },
|
||
{ title: '尝试', key: 'attempts', width: 58, align: 'center', className: MONO,
|
||
render: (_: any, t: any) => `${t.attempts}/${t.max_attempts}` },
|
||
{ title: '进度', key: 'progress', width: 100, align: 'center',
|
||
render: (_: any, t: any) => <ProgressBar value={Math.round((t.progress || 0) * 100)} /> },
|
||
{ title: '耗时', key: 'elapsed', width: 82, align: 'right', className: MONO, render: (_: any, t: any) => (
|
||
t.elapsed_ms ? `${(t.elapsed_ms / 1000).toFixed(1)}s`
|
||
: t.queue_wait_ms ? `排队 ${(t.queue_wait_ms / 1000).toFixed(1)}s` : '—'
|
||
) },
|
||
{ title: '状态', key: 'status', width: 168, render: (_: any, t: any) => (
|
||
<>
|
||
<Status value={t.status} />{' '}
|
||
<span className={MUTED}>{fmtAgo(t.updated_at)}</span>
|
||
{/* 心跳停服只在这一行说结论,长解释挂 title:整表级的说明在卡头 sub 里。
|
||
原来这里是三行红字,行高从 42 顶到 125。 */}
|
||
{t.stale
|
||
? <Tag size="sm" tone="warn" className="ml-1"
|
||
title={`执行体超过 ${fmtAge(t.heartbeat_age_seconds)}没有报活:多半是那台机器上的模型服务或平台进程中断过,产物与断点都留着,平台回收后会自动续跑`}>
|
||
心跳停止
|
||
</Tag>
|
||
: null}
|
||
</>
|
||
) },
|
||
{ title: '错误 / 检查点', key: 'error', render: (_: any, t: any) => {
|
||
const detail = [
|
||
t.error_message ? `${t.error_code || 'error'} ${t.error_message}` : '',
|
||
t.checkpoint?.last_note || ''
|
||
].filter(Boolean).join(' / ')
|
||
return <>
|
||
<Clamp title={detail}>
|
||
{t.error_message ? <span className="text-error">{t.error_code} {t.error_message}</span> : null}
|
||
{t.checkpoint?.last_note ? <span> {t.checkpoint.last_note}</span>
|
||
: Object.keys(t.checkpoint || {}).length
|
||
? <span className={MUTED_MONO}> checkpoint: {JSON.stringify(t.checkpoint)}</span> : null}
|
||
</Clamp>
|
||
{t.output_url ? <ExtLink href={t.output_url}>产物</ExtLink> : null}
|
||
</>
|
||
} },
|
||
{ title: '操作', key: 'actions', width: 112, align: 'right', render: (_: any, t: any) => (
|
||
<Row className="justify-end">
|
||
{['failed', 'cancelled'].includes(t.status)
|
||
? <Button icon={<IconRetry />} size="sm" onClick={() => retryTask(t)}>重试</Button> : null}
|
||
{ACTIVE_STATUSES.includes(t.status)
|
||
? <Button icon={<IconClose />} size="sm" onClick={() => cancelTask(t)}>取消</Button> : null}
|
||
{t.status === 'succeeded' || t.status === 'skipped' ? <span className={MUTED}>—</span> : null}
|
||
</Row>
|
||
) }
|
||
]}
|
||
/>
|
||
</Panel>
|
||
|
||
<Toolbar
|
||
info="模型配置已迁移至独立管理中心"
|
||
actions={<LinkButton icon={<IconApi />} to="/models" type="primary" title="统一维护大模型、图像、视频与声音模型的适配器、默认项、并发、限流、价格、能力与连接探测。调度中心只负责项目任务编排与执行。">打开模型管理中心</LinkButton>} />
|
||
</PageStack>
|
||
)
|
||
}
|