feat(monitor): 取消失败发布并修正危险按钮对比度
- Parse-monitor: the batch-retry button rendered red-on-red because weknoraMonitor.css overrode the global .danger style with text color only; make .danger a filled red button with proper hover/disabled states. - Add operator cancel: 批量取消所选 / per-task 不再处理 buttons move failed/stalled publications to a new 'cancelled' state in one audited batch operation (POST /api/v1/test-publications/cancel-batch, idempotent, migration 000041 widens the CHECK constraints). Queued upload jobs are cancelled, open dead letters abandoned; source records and spool files stay intact so re-marking in the catalog can retry later. - Queue status filter and labels learn 已取消; OpenAPI contract updated.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { newOperationID } from './operationKey'
|
||||
export type IngestState = 'pending' | 'uploading' | 'uploaded' | 'failed'
|
||||
export type ProcessingState = 'planned' | 'pending' | 'processing' | 'finalizing' | 'completed' | 'failed' | 'stalled'
|
||||
export type ProcessingState = 'planned' | 'pending' | 'processing' | 'finalizing' | 'completed' | 'failed' | 'stalled' | 'cancelled'
|
||||
|
||||
export interface TestPublication {
|
||||
id: string
|
||||
@@ -50,7 +50,7 @@ export interface StartTestPublicationsResult {
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null
|
||||
const isCount = (value: unknown): value is number => typeof value === 'number' && Number.isInteger(value) && value >= 0
|
||||
const ingestStates = new Set<IngestState>(['pending', 'uploading', 'uploaded', 'failed'])
|
||||
const processingStates = new Set<ProcessingState>(['planned', 'pending', 'processing', 'finalizing', 'completed', 'failed', 'stalled'])
|
||||
const processingStates = new Set<ProcessingState>(['planned', 'pending', 'processing', 'finalizing', 'completed', 'failed', 'stalled', 'cancelled'])
|
||||
|
||||
function parseTestPublication(value: unknown): TestPublication {
|
||||
if (!isRecord(value) || typeof value.id !== 'string' || typeof value.title !== 'string' ||
|
||||
@@ -172,6 +172,34 @@ export async function retryPublicationsBatch(publicationIds: string[], reason: s
|
||||
|
||||
export interface JobFailure { id: string; job_id: string; job_type: string; publication_id?: string; source_item_id?: string; error_code: string; attempt: number; max_attempts_at_failure: number; change_set_id?: string; action?: string; target_kb_id?: string; state: 'open' | 'requeued' | 'abandoned'; created_at: string; doc_name?: string; last_error?: string }
|
||||
|
||||
export async function cancelPublicationsBatch(publicationIds: string[], reason: string): Promise<RetryPublicationsBatchResult> {
|
||||
const response = await fetch('/api/v1/test-publications/cancel-batch', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
body: JSON.stringify({ publication_ids: publicationIds, reason }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as { error?: string } | null
|
||||
throw new Error(body?.error ?? `批量取消失败(HTTP ${response.status})`)
|
||||
}
|
||||
const value = await response.json() as unknown
|
||||
if (!isRecord(value) || !isRecord(value.data) || !Array.isArray(value.data.outcomes)) throw new Error('批量取消响应无效')
|
||||
const data = value.data as Record<string, unknown>
|
||||
const outcomes = Array.isArray(data.outcomes) ? data.outcomes : []
|
||||
return {
|
||||
batch_key: typeof data.batch_key === 'string' ? data.batch_key : '',
|
||||
total: isCount(data.total) ? data.total : 0,
|
||||
started: isCount(data.started) ? data.started : 0,
|
||||
already_running: isCount(data.already_running) ? data.already_running : 0,
|
||||
not_retryable: isCount(data.not_retryable) ? data.not_retryable : 0,
|
||||
outcomes: outcomes.filter(isRecord).map((item) => ({
|
||||
publication_id: typeof item.publication_id === 'string' ? item.publication_id : '',
|
||||
result: item.result === 'started' || item.result === 'already_running' || item.result === 'not_retryable' ? item.result : 'not_retryable',
|
||||
detail: typeof item.detail === 'string' ? item.detail : undefined,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchJobFailures(signal?: AbortSignal): Promise<JobFailure[]> {
|
||||
const response = await fetch('/api/v1/job-failures?state=open&limit=50', { headers: { Accept: 'application/json' }, signal })
|
||||
if (!response.ok) throw new Error(`加载失败队列失败(HTTP ${response.status})`)
|
||||
|
||||
Reference in New Issue
Block a user