diff --git a/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs b/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs index c38c5d4..d344ac9 100644 --- a/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs +++ b/apps/desktop/src-tauri/src/business/services/volcano_video_service.rs @@ -307,6 +307,8 @@ impl VolcanoVideoService { let mut attempts = 0; let max_attempts = 60; // 最多轮询60次(约10分钟) + let mut consecutive_failures = 0; + let max_consecutive_failures = 3; // 连续失败3次就标记为失败 while attempts < max_attempts { tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; @@ -314,6 +316,8 @@ impl VolcanoVideoService { match self.check_task_status(&task_id).await { Ok(status_response) => { + // 重置连续失败计数器 + consecutive_failures = 0; if let Some(data) = status_response.data { let mut record = self.repository.get_by_id(&record_id).await? .ok_or_else(|| anyhow!("找不到视频生成记录: {}", record_id))?; @@ -355,6 +359,21 @@ impl VolcanoVideoService { } Err(e) => { warn!("检查任务状态失败: {}", e); + consecutive_failures += 1; + + // 如果连续失败次数达到上限,标记任务为失败 + if consecutive_failures >= max_consecutive_failures { + error!("连续{}次检查任务状态失败,标记任务为失败: {}", max_consecutive_failures, e); + let mut record = self.repository.get_by_id(&record_id).await? + .ok_or_else(|| anyhow!("找不到视频生成记录: {}", record_id))?; + record.mark_as_failed( + format!("连续{}次API调用失败: {}", max_consecutive_failures, e), + Some("API_CONSECUTIVE_FAILURES".to_string()) + ); + self.repository.update(&record).await?; + return Err(anyhow!("连续{}次检查任务状态失败", max_consecutive_failures)); + } + continue; } }