发布管理:maintenanceSummary 只看 job.state === 'failed' 就给 held 处置文案; 窗口已 released 的旧作业(libsync-internal-1793399248431728863)因此自相矛盾。 改为仅 held 时给 recoveryError,已释放时给 releasedFailure(如实记录失败,不提供强制成功)。 版本记录:LoadVersionHistorySyncState 把可空的 finished_at 扫进 time.Time; 部署重启触发的同步在"进行中"时该列为 NULL,扫描失败使整页 500 (nginx access log:GET /api/v1/version-history?limit=30 → 500,74 字节错误体)。 改为指针接值再判空。前端同时区分"未配置/加载失败"并显示服务端 code。 RED/GREEN:新增 Go 集成用例(NULL finished_at)、两条前端用例; make verify 16/16 通过(local 档案)。
This commit is contained in:
+139
-35
@@ -1,6 +1,7 @@
|
||||
import { newOperationID } from './operationKey'
|
||||
export type IngestState = 'pending' | 'uploading' | 'uploaded' | 'failed'
|
||||
export type ProcessingState = 'planned' | 'pending' | 'processing' | 'finalizing' | 'completed' | 'failed' | 'stalled' | 'cancelled'
|
||||
export type ProcessingState =
|
||||
'planned' | 'pending' | 'processing' | 'finalizing' | 'completed' | 'failed' | 'stalled' | 'cancelled'
|
||||
|
||||
export interface TestPublication {
|
||||
id: string
|
||||
@@ -35,7 +36,7 @@ export interface AcceptanceRecord {
|
||||
|
||||
export interface TestPublicationQuery {
|
||||
/** removal: 'required' 只取「被禁止导入但仍存活在测试库」的条目(解析监控 → 需下架)。 */
|
||||
removal?: 'required'
|
||||
removal?: 'required'
|
||||
// A single state, or several at once (joined into a comma list server-side).
|
||||
processing_state: ProcessingState | '' | ProcessingState[]
|
||||
target_scope?: 'internal' | 'external' | ''
|
||||
@@ -53,16 +54,36 @@ 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', 'cancelled'])
|
||||
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' ||
|
||||
typeof value.ingest_state !== 'string' || !ingestStates.has(value.ingest_state as IngestState) ||
|
||||
typeof value.processing_state !== 'string' || !processingStates.has(value.processing_state as ProcessingState) ||
|
||||
typeof value.retrieval_state !== 'string' || (value.target_scope !== 'internal' && value.target_scope !== 'external') ||
|
||||
if (
|
||||
!isRecord(value) ||
|
||||
typeof value.id !== 'string' ||
|
||||
typeof value.title !== 'string' ||
|
||||
typeof value.ingest_state !== 'string' ||
|
||||
!ingestStates.has(value.ingest_state as IngestState) ||
|
||||
typeof value.processing_state !== 'string' ||
|
||||
!processingStates.has(value.processing_state as ProcessingState) ||
|
||||
typeof value.retrieval_state !== 'string' ||
|
||||
(value.target_scope !== 'internal' && value.target_scope !== 'external') ||
|
||||
typeof value.change_set_id !== 'string' ||
|
||||
(value.change_type !== 'added' && value.change_type !== 'updated') || typeof value.can_start !== 'boolean' ||
|
||||
!isCount(value.retry_count) || typeof value.last_error !== 'string' || typeof value.can_retry !== 'boolean' || typeof value.updated_at !== 'string') {
|
||||
(value.change_type !== 'added' && value.change_type !== 'updated') ||
|
||||
typeof value.can_start !== 'boolean' ||
|
||||
!isCount(value.retry_count) ||
|
||||
typeof value.last_error !== 'string' ||
|
||||
typeof value.can_retry !== 'boolean' ||
|
||||
typeof value.updated_at !== 'string'
|
||||
) {
|
||||
throw new Error('invalid test publication response')
|
||||
}
|
||||
return {
|
||||
@@ -83,7 +104,13 @@ function parseTestPublication(value: unknown): TestPublication {
|
||||
}
|
||||
|
||||
export function parseTestPublicationsResponse(value: unknown): TestPublicationPage {
|
||||
if (!isRecord(value) || !Array.isArray(value.data) || !isCount(value.total) || !isCount(value.limit) || !isCount(value.offset)) {
|
||||
if (
|
||||
!isRecord(value) ||
|
||||
!Array.isArray(value.data) ||
|
||||
!isCount(value.total) ||
|
||||
!isCount(value.limit) ||
|
||||
!isCount(value.offset)
|
||||
) {
|
||||
throw new Error('invalid test publications response')
|
||||
}
|
||||
return {
|
||||
@@ -94,14 +121,24 @@ export function parseTestPublicationsResponse(value: unknown): TestPublicationPa
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchTestPublications(query: TestPublicationQuery, signal?: AbortSignal): Promise<TestPublicationPage> {
|
||||
export async function fetchTestPublications(
|
||||
query: TestPublicationQuery,
|
||||
signal?: AbortSignal
|
||||
): Promise<TestPublicationPage> {
|
||||
const parameters = new URLSearchParams()
|
||||
if (query.processing_state) parameters.set('processing_state', Array.isArray(query.processing_state) ? query.processing_state.join(',') : query.processing_state)
|
||||
if (query.processing_state)
|
||||
parameters.set(
|
||||
'processing_state',
|
||||
Array.isArray(query.processing_state) ? query.processing_state.join(',') : query.processing_state
|
||||
)
|
||||
if (query.target_scope) parameters.set('target_scope', query.target_scope)
|
||||
if (query.removal) parameters.set('removal', query.removal)
|
||||
parameters.set('limit', String(query.limit))
|
||||
parameters.set('offset', String(query.offset))
|
||||
const response = await fetch(`/api/v1/test-publications?${parameters.toString()}`, { headers: { Accept: 'application/json' }, signal })
|
||||
const response = await fetch(`/api/v1/test-publications?${parameters.toString()}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
signal,
|
||||
})
|
||||
if (!response.ok) throw new Error(`加载测试发布失败(HTTP ${response.status})`)
|
||||
return parseTestPublicationsResponse(await response.json())
|
||||
}
|
||||
@@ -127,28 +164,37 @@ export async function startPublicationRemoval(publicationId: string): Promise<{
|
||||
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
|
||||
const value = (await response.json()) as unknown
|
||||
if (!isRecord(value) || typeof value.job_id !== 'string') throw new Error('下架响应无效')
|
||||
return { job_id: value.job_id }
|
||||
}
|
||||
|
||||
export async function fetchAcceptanceResults(publicationId: string, signal?: AbortSignal): Promise<AcceptanceRecord[]> {
|
||||
const response = await fetch(`/api/v1/test-publications/${encodeURIComponent(publicationId)}/acceptance`, { headers: { Accept: 'application/json' }, signal })
|
||||
const response = await fetch(`/api/v1/test-publications/${encodeURIComponent(publicationId)}/acceptance`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
signal,
|
||||
})
|
||||
if (!response.ok) throw new Error(`加载验收结果失败(HTTP ${response.status})`)
|
||||
const value = await response.json() as unknown
|
||||
const value = (await response.json()) as unknown
|
||||
if (!isRecord(value) || !Array.isArray(value.data)) throw new Error('invalid acceptance response')
|
||||
return value.data as AcceptanceRecord[]
|
||||
}
|
||||
|
||||
export async function retryPublication(publicationId: string): Promise<void> {
|
||||
const response = await fetch(`/api/v1/test-publications/${encodeURIComponent(publicationId)}/retry`, { method: 'POST', headers: { Accept: 'application/json', 'Idempotency-Key': newOperationID() } })
|
||||
const response = await fetch(`/api/v1/test-publications/${encodeURIComponent(publicationId)}/retry`, {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
})
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as { error?: string } | null
|
||||
throw new Error(body?.error ?? `重试失败(HTTP ${response.status})`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function startTestPublications(publicationIds: string[], reason: string): Promise<StartTestPublicationsResult> {
|
||||
export async function startTestPublications(
|
||||
publicationIds: string[],
|
||||
reason: string
|
||||
): Promise<StartTestPublicationsResult> {
|
||||
const response = await fetch('/api/v1/test-publications/start', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
@@ -158,8 +204,15 @@ export async function startTestPublications(publicationIds: string[], reason: st
|
||||
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) || !isCount(value.data.selected) || !isCount(value.data.started) || !isCount(value.data.already_started) || !isCount(value.data.unavailable)) {
|
||||
const value = (await response.json()) as unknown
|
||||
if (
|
||||
!isRecord(value) ||
|
||||
!isRecord(value.data) ||
|
||||
!isCount(value.data.selected) ||
|
||||
!isCount(value.data.started) ||
|
||||
!isCount(value.data.already_started) ||
|
||||
!isCount(value.data.unavailable)
|
||||
) {
|
||||
throw new Error('invalid processing start response')
|
||||
}
|
||||
return {
|
||||
@@ -169,10 +222,24 @@ export async function startTestPublications(publicationIds: string[], reason: st
|
||||
unavailable: value.data.unavailable,
|
||||
}
|
||||
}
|
||||
export interface RetryOutcome { publication_id: string; result: 'started' | 'already_running' | 'not_retryable'; detail?: string }
|
||||
export interface RetryPublicationsBatchResult { batch_key: string; total: number; started: number; already_running: number; not_retryable: number; outcomes: RetryOutcome[] }
|
||||
export interface RetryOutcome {
|
||||
publication_id: string
|
||||
result: 'started' | 'already_running' | 'not_retryable'
|
||||
detail?: string
|
||||
}
|
||||
export interface RetryPublicationsBatchResult {
|
||||
batch_key: string
|
||||
total: number
|
||||
started: number
|
||||
already_running: number
|
||||
not_retryable: number
|
||||
outcomes: RetryOutcome[]
|
||||
}
|
||||
|
||||
export async function retryPublicationsBatch(publicationIds: string[], reason: string): Promise<RetryPublicationsBatchResult> {
|
||||
export async function retryPublicationsBatch(
|
||||
publicationIds: string[],
|
||||
reason: string
|
||||
): Promise<RetryPublicationsBatchResult> {
|
||||
const response = await fetch('/api/v1/test-publications/retry-batch', {
|
||||
method: 'POST',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': newOperationID() },
|
||||
@@ -182,8 +249,9 @@ export async function retryPublicationsBatch(publicationIds: string[], reason: s
|
||||
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 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 {
|
||||
@@ -194,15 +262,37 @@ export async function retryPublicationsBatch(publicationIds: string[], reason: s
|
||||
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',
|
||||
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 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 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> {
|
||||
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() },
|
||||
@@ -212,8 +302,9 @@ export async function cancelPublicationsBatch(publicationIds: string[], reason:
|
||||
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 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 {
|
||||
@@ -224,21 +315,34 @@ export async function cancelPublicationsBatch(publicationIds: string[], reason:
|
||||
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',
|
||||
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 })
|
||||
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})`)
|
||||
const value = await response.json() as unknown
|
||||
const value = (await response.json()) as unknown
|
||||
if (!isRecord(value) || !isRecord(value.data) || !Array.isArray(value.data.items)) throw new Error('失败队列响应无效')
|
||||
return value.data.items as JobFailure[]
|
||||
}
|
||||
|
||||
export interface RequeuedArtifactFetch { failure_id: string; job_id: string; version_id: string; round: number; doc_name?: string; already_queued: boolean }
|
||||
export interface RequeuedArtifactFetch {
|
||||
failure_id: string
|
||||
job_id: string
|
||||
version_id: string
|
||||
round: number
|
||||
doc_name?: string
|
||||
already_queued: boolean
|
||||
}
|
||||
|
||||
// 源头取件死信重排:取件任务的幂等键绑在版本上,失败那次已占住它,所以重新标注
|
||||
// 同一文件不会再入队;这里让后端按新轮次重新排队(新键),并复位意图状态。
|
||||
@@ -252,7 +356,7 @@ export async function requeueJobFailure(failureId: string, reason: string): Prom
|
||||
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
|
||||
const value = (await response.json()) as unknown
|
||||
if (!isRecord(value) || !isRecord(value.data)) throw new Error('重新取件响应无效')
|
||||
const data = value.data as Record<string, unknown>
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user