diff --git a/apps/desktop/src-tauri/src/business/services/video_classification_queue.rs b/apps/desktop/src-tauri/src/business/services/video_classification_queue.rs index ea9f031..94da47e 100644 --- a/apps/desktop/src-tauri/src/business/services/video_classification_queue.rs +++ b/apps/desktop/src-tauri/src/business/services/video_classification_queue.rs @@ -266,7 +266,17 @@ impl VideoClassificationQueue { sleep(self.processing_delay).await; } Ok(None) => { - // 没有待处理任务,等待 + // 没有待处理任务,检查是否应该自动停止 + if let Ok(should_stop) = self.check_should_auto_stop().await { + if should_stop { + println!("🛑 检测到没有任务需要处理,自动停止队列"); + let mut status = self.status.write().await; + *status = QueueStatus::Stopped; + break; + } + } + + // 继续等待 sleep(Duration::from_secs(5)).await; } Err(e) => { @@ -286,6 +296,31 @@ impl VideoClassificationQueue { println!("AI视频分类队列处理循环已退出"); } + /// 检查是否应该自动停止队列 + /// 当等待中=0且处理中=0时,说明没有任务需要处理 + async fn check_should_auto_stop(&self) -> Result { + // 获取当前统计信息 + let stats = self.stats.read().await; + + // 检查是否有待处理或正在处理的任务 + let has_pending = stats.pending_tasks > 0; + let has_processing = stats.processing_tasks > 0; + let has_current_task = self.current_task.lock().await.is_some(); + + // 如果没有待处理、没有正在处理、也没有当前任务,则可以停止 + let should_stop = !has_pending && !has_processing && !has_current_task; + + if should_stop { + println!("📊 队列状态检查:"); + println!(" 等待中任务: {}", stats.pending_tasks); + println!(" 处理中任务: {}", stats.processing_tasks); + println!(" 当前任务: {}", if has_current_task { "有" } else { "无" }); + println!(" 结论: 没有任务需要处理,准备自动停止"); + } + + Ok(should_stop) + } + /// 处理下一个任务 async fn process_next_task(&self) -> Result> { println!("🔍 查找待处理任务..."); diff --git a/apps/desktop/src/components/AiAnalysisLogViewer.tsx b/apps/desktop/src/components/AiAnalysisLogViewer.tsx index ff05bba..538c188 100644 --- a/apps/desktop/src/components/AiAnalysisLogViewer.tsx +++ b/apps/desktop/src/components/AiAnalysisLogViewer.tsx @@ -173,21 +173,6 @@ export const AiAnalysisLogViewer: React.FC = ({ projec } }; - // 创建测试数据 - const handleCreateTestData = async () => { - try { - const result = await invoke('create_test_ai_analysis_logs', { - projectId, - }); - console.log('创建测试数据结果:', result); - // 重新加载数据 - loadLogs(); - loadStats(); - } catch (err) { - console.error('创建测试数据失败:', err); - } - }; - // 重试失败任务 const handleRetryTask = async (taskId: string) => { try { @@ -354,13 +339,6 @@ export const AiAnalysisLogViewer: React.FC = ({ projec > -