celery 升级优化V2 | 日志调整 | 前端BUG修复

This commit is contained in:
2026-07-23 12:07:23 +08:00
parent 06bf5c4db7
commit 2931e67226
37 changed files with 3122 additions and 1613 deletions
+50 -85
View File
@@ -2,6 +2,10 @@ export interface GenerationStatusLike {
status?: string | null;
displayStatus?: string | null;
pipelineStage?: string | null;
clientStatus?: string | null;
shouldPoll?: boolean | null;
canGenerate?: boolean | null;
canRetry?: boolean | null;
}
export type GenerationUiColor = 'default' | 'processing' | 'warning' | 'success' | 'error' | 'blue' | 'orange' | 'purple';
@@ -17,42 +21,34 @@ export interface GenerationUiState {
isSuccess: boolean;
isFailure: boolean;
isTerminal: boolean;
canGenerate: boolean;
canRetry: boolean;
shouldPoll: boolean;
}
const ACTIVE_STATUS_KEYS = new Set([
'pending',
'optimizing',
'prompt_optimized',
'generating',
]);
const CLIENT_STATUS_MAP: Record<string, string> = {
prompt_processing: 'optimizing',
ready: 'prompt_optimized',
generating: 'generating',
success: 'completed',
failure: 'failed',
};
const ACTIVE_STATUS_KEYS = new Set(['pending', 'optimizing', 'generating']);
const ACTIVE_PIPELINE_STAGES = new Set([
'queued',
'preparing',
'creating_provider_task',
'provider_result_staged',
'waiting_remote',
'polling',
'result_ready',
'download_queued',
'downloading',
'retry_waiting',
'upscale_queued',
'upscale_processing',
'upscale_polling',
'upscale_downloading',
'upscale_finalizing',
'upscale_retry_waiting',
'queued', 'preparing', 'creating_provider_task', 'provider_result_staged',
'waiting_remote', 'polling', 'result_ready', 'download_queued', 'downloading',
'retry_waiting', 'recovery_inconsistent', 'upscale_queued', 'upscale_processing',
'upscale_polling', 'upscale_downloading', 'upscale_finalizing', 'upscale_retry_waiting',
]);
const SUCCESS_KEYS = new Set(['completed', 'done']);
const FAILURE_KEYS = new Set(['failed', 'timeout', 'download_failed', 'upscale_failed']);
const TERMINAL_KEYS = new Set([...SUCCESS_KEYS, ...FAILURE_KEYS, 'deleted']);
const LABELS: Record<string, string> = {
pending: '生成中',
optimizing: '生成中',
prompt_optimized: '生成',
pending: '待处理',
optimizing: '提词处理中',
prompt_optimized: '生成',
generating: '生成中',
queued: '生成中',
preparing: '生成中',
@@ -64,15 +60,16 @@ const LABELS: Record<string, string> = {
download_queued: '生成中',
downloading: '生成中',
retry_waiting: '生成中',
recovery_inconsistent: '生成中',
upscale_queued: '生成中',
upscale_processing: '生成中',
upscale_polling: '生成中',
upscale_downloading: '生成中',
upscale_finalizing: '生成中',
upscale_retry_waiting: '生成中',
completed: '已完成',
done: '已完成',
timeout: '生成超时',
completed: '成',
done: '成',
timeout: '失败',
download_failed: '失败',
upscale_failed: '失败',
failed: '失败',
@@ -80,33 +77,15 @@ const LABELS: Record<string, string> = {
};
const COLOR_MAP: Record<string, GenerationUiColor> = {
pending: 'default',
optimizing: 'processing',
prompt_optimized: 'processing',
generating: 'warning',
queued: 'processing',
preparing: 'processing',
creating_provider_task: 'processing',
provider_result_staged: 'processing',
waiting_remote: 'processing',
polling: 'processing',
result_ready: 'processing',
download_queued: 'processing',
downloading: 'processing',
retry_waiting: 'orange',
upscale_queued: 'purple',
upscale_processing: 'purple',
upscale_polling: 'purple',
upscale_downloading: 'purple',
upscale_finalizing: 'purple',
upscale_retry_waiting: 'orange',
completed: 'success',
done: 'success',
failed: 'error',
timeout: 'error',
download_failed: 'error',
upscale_failed: 'error',
deleted: 'default',
pending: 'default', optimizing: 'processing', prompt_optimized: 'blue', generating: 'processing',
queued: 'processing', preparing: 'processing', creating_provider_task: 'processing',
provider_result_staged: 'processing', waiting_remote: 'processing', polling: 'processing',
result_ready: 'processing', download_queued: 'processing', downloading: 'processing',
retry_waiting: 'orange', recovery_inconsistent: 'orange', upscale_queued: 'purple',
upscale_processing: 'purple', upscale_polling: 'purple', upscale_downloading: 'purple',
upscale_finalizing: 'purple', upscale_retry_waiting: 'orange', completed: 'success',
done: 'success', failed: 'error', timeout: 'error', download_failed: 'error',
upscale_failed: 'error', deleted: 'default',
};
const normalize = (value?: string | null): string => String(value || '').trim().toLowerCase();
@@ -121,45 +100,28 @@ export const getGenerationStatusColor = (key?: string | null): GenerationUiColor
return COLOR_MAP[normalized] || 'default';
};
const firstMatching = (values: string[], keys: Set<string>): string => (
values.find((value) => keys.has(value)) || ''
);
export const resolveGenerationUiState = (value: GenerationStatusLike): GenerationUiState => {
const status = normalize(value.status);
const displayStatus = normalize(value.displayStatus);
const pipelineStage = normalize(value.pipelineStage);
const values = [displayStatus, status, pipelineStage].filter(Boolean);
const clientStatus = normalize(value.clientStatus);
const mappedClientStatus = CLIENT_STATUS_MAP[clientStatus] || '';
const failureKey = FAILURE_KEYS.has(pipelineStage)
? pipelineStage
: firstMatching([displayStatus, status], FAILURE_KEYS);
const deletedKey = firstMatching(values, new Set(['deleted']));
const successKey = firstMatching(values, SUCCESS_KEYS);
let effectiveKey = '';
if (failureKey) {
effectiveKey = failureKey;
} else if (deletedKey) {
effectiveKey = deletedKey;
} else if (ACTIVE_PIPELINE_STAGES.has(pipelineStage)) {
let effectiveKey = mappedClientStatus || displayStatus || status || pipelineStage || 'pending';
if (FAILURE_KEYS.has(pipelineStage) || FAILURE_KEYS.has(status) || FAILURE_KEYS.has(displayStatus)) {
effectiveKey = FAILURE_KEYS.has(pipelineStage) ? pipelineStage : (FAILURE_KEYS.has(status) ? status : displayStatus);
} else if (SUCCESS_KEYS.has(status) || SUCCESS_KEYS.has(displayStatus)) {
effectiveKey = SUCCESS_KEYS.has(status) ? status : displayStatus;
} else if (!mappedClientStatus && pipelineStage && ACTIVE_PIPELINE_STAGES.has(pipelineStage)) {
effectiveKey = pipelineStage;
} else if (successKey) {
effectiveKey = successKey;
} else if (pipelineStage) {
effectiveKey = pipelineStage;
} else {
effectiveKey = displayStatus || status || 'pending';
}
const isFailure = FAILURE_KEYS.has(effectiveKey);
const isSuccess = SUCCESS_KEYS.has(effectiveKey);
const isActive = !isFailure && !isSuccess && effectiveKey !== 'deleted' && (
ACTIVE_PIPELINE_STAGES.has(pipelineStage)
|| ACTIVE_STATUS_KEYS.has(displayStatus)
|| ACTIVE_STATUS_KEYS.has(status)
|| ACTIVE_PIPELINE_STAGES.has(effectiveKey)
);
const shouldPoll = typeof value.shouldPoll === 'boolean'
? value.shouldPoll
: (!isFailure && !isSuccess && (ACTIVE_STATUS_KEYS.has(status) || ACTIVE_PIPELINE_STAGES.has(pipelineStage)));
const isActive = shouldPoll;
return {
status,
@@ -172,6 +134,9 @@ export const resolveGenerationUiState = (value: GenerationStatusLike): Generatio
isSuccess,
isFailure,
isTerminal: TERMINAL_KEYS.has(effectiveKey),
canGenerate: typeof value.canGenerate === 'boolean' ? value.canGenerate : status === 'prompt_optimized',
canRetry: typeof value.canRetry === 'boolean' ? value.canRetry : isFailure,
shouldPoll,
};
};