fix: 修复AI视频分类进度数据不一致问题
This commit is contained in:
parent
943a22a85e
commit
483ea64413
|
|
@ -28,6 +28,7 @@ export const VideoClassificationProgress: React.FC<VideoClassificationProgressPr
|
||||||
taskProgress,
|
taskProgress,
|
||||||
refreshQueueStatus,
|
refreshQueueStatus,
|
||||||
refreshTaskProgress,
|
refreshTaskProgress,
|
||||||
|
getProjectQueueStatus,
|
||||||
getProjectTaskProgress,
|
getProjectTaskProgress,
|
||||||
getClassificationStats,
|
getClassificationStats,
|
||||||
pauseQueue,
|
pauseQueue,
|
||||||
|
|
@ -45,6 +46,15 @@ export const VideoClassificationProgress: React.FC<VideoClassificationProgressPr
|
||||||
const [stats, setStats] = useState<ClassificationStats | null>(null);
|
const [stats, setStats] = useState<ClassificationStats | null>(null);
|
||||||
const [isExpanded, setIsExpanded] = useState(false);
|
const [isExpanded, setIsExpanded] = useState(false);
|
||||||
|
|
||||||
|
// 刷新队列状态的方法
|
||||||
|
const refreshQueueStats = useCallback(async () => {
|
||||||
|
if (projectId) {
|
||||||
|
await getProjectQueueStatus(projectId);
|
||||||
|
} else {
|
||||||
|
await refreshQueueStatus();
|
||||||
|
}
|
||||||
|
}, [projectId, getProjectQueueStatus, refreshQueueStatus]);
|
||||||
|
|
||||||
// 刷新任务进度的方法
|
// 刷新任务进度的方法
|
||||||
const refreshProgress = useCallback(async () => {
|
const refreshProgress = useCallback(async () => {
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
|
|
@ -59,7 +69,7 @@ export const VideoClassificationProgress: React.FC<VideoClassificationProgressPr
|
||||||
if (!autoRefresh) return;
|
if (!autoRefresh) return;
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
await refreshQueueStatus();
|
await refreshQueueStats();
|
||||||
await refreshProgress();
|
await refreshProgress();
|
||||||
|
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
|
|
@ -73,17 +83,17 @@ export const VideoClassificationProgress: React.FC<VideoClassificationProgressPr
|
||||||
}, refreshInterval);
|
}, refreshInterval);
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [autoRefresh, refreshInterval, projectId, refreshQueueStatus, refreshProgress, getClassificationStats]);
|
}, [autoRefresh, refreshInterval, projectId, refreshQueueStats, refreshProgress, getClassificationStats]);
|
||||||
|
|
||||||
// 初始加载
|
// 初始加载
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshQueueStatus();
|
refreshQueueStats();
|
||||||
refreshProgress();
|
refreshProgress();
|
||||||
|
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
getClassificationStats(projectId).then(setStats).catch(console.error);
|
getClassificationStats(projectId).then(setStats).catch(console.error);
|
||||||
}
|
}
|
||||||
}, [projectId, refreshQueueStatus, refreshProgress, getClassificationStats]);
|
}, [projectId, refreshQueueStats, refreshProgress, getClassificationStats]);
|
||||||
|
|
||||||
// 获取状态颜色和图标
|
// 获取状态颜色和图标
|
||||||
const getStatusInfo = (status: string) => {
|
const getStatusInfo = (status: string) => {
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ interface VideoClassificationState {
|
||||||
// Actions
|
// Actions
|
||||||
startClassification: (request: BatchClassificationRequest) => Promise<string[]>;
|
startClassification: (request: BatchClassificationRequest) => Promise<string[]>;
|
||||||
getQueueStatus: () => Promise<QueueStats>;
|
getQueueStatus: () => Promise<QueueStats>;
|
||||||
|
getProjectQueueStatus: (projectId: string) => Promise<QueueStats>;
|
||||||
getTaskProgress: (taskId: string) => Promise<TaskProgress | null>;
|
getTaskProgress: (taskId: string) => Promise<TaskProgress | null>;
|
||||||
getAllTaskProgress: () => Promise<Record<string, TaskProgress>>;
|
getAllTaskProgress: () => Promise<Record<string, TaskProgress>>;
|
||||||
getProjectTaskProgress: (projectId: string) => Promise<Record<string, TaskProgress>>;
|
getProjectTaskProgress: (projectId: string) => Promise<Record<string, TaskProgress>>;
|
||||||
|
|
@ -129,6 +130,18 @@ export const useVideoClassificationStore = create<VideoClassificationState>((set
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getProjectQueueStatus: async (projectId: string) => {
|
||||||
|
try {
|
||||||
|
const stats = await invoke<QueueStats>('get_project_classification_queue_status', { projectId });
|
||||||
|
set({ queueStats: stats });
|
||||||
|
return stats;
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = typeof error === 'string' ? error : '获取项目队列状态失败';
|
||||||
|
set({ error: errorMessage });
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getTaskProgress: async (taskId: string) => {
|
getTaskProgress: async (taskId: string) => {
|
||||||
try {
|
try {
|
||||||
const progress = await invoke<TaskProgress | null>('get_classification_task_progress', { taskId });
|
const progress = await invoke<TaskProgress | null>('get_classification_task_progress', { taskId });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue