diff --git a/scripts/batch-export.js b/scripts/batch-export.js index 8b481a3..accbebe 100644 --- a/scripts/batch-export.js +++ b/scripts/batch-export.js @@ -92,46 +92,37 @@ class BatchVideoExporter { /** 生成剪辑计划 */ async generateEditPlan(projectId) { this.log(`开始为项目 ${projectId} 生成剪辑计划...`); - - const maxRetryTime = 10 * 60 * 1000; // 10分钟 - const retryInterval = 8 * 1000; // 8秒 - const maxAttempts = Math.floor(maxRetryTime / retryInterval); - - let attempts = 0; - - while (attempts < maxAttempts) { - attempts++; - + const maxAttempts = 3; // 最多重试3次 + const retryDelayMs = Number(this.config.retryDelay || 3000); + + for (let attempt = 1; attempt <= maxAttempts; attempt++) { try { - this.log(`项目 ${projectId}: 第${attempts}次尝试获取剪辑计划...`); - - const response = await this.makeRequest('/edit-plan/generate-by-project', { - project_id: projectId + this.log(`项目 ${projectId}: 第${attempt}次尝试获取剪辑计划...`); + + const response = await this.makeRequest('/edit-plan/generate-by-project', { + project_id: projectId }); - + if (response.code === 0 && response.data && response.data.success && response.data.editing_plan) { this.log(`项目 ${projectId}: 剪辑计划生成成功`); return response.data.editing_plan; } - - if (attempts >= maxAttempts) { - throw new Error(`剪辑计划生成失败: ${response.message || '未知错误'}`); - } - - this.log(`项目 ${projectId}: 第${attempts}次尝试失败,${retryInterval/1000}秒后重试...`); - await new Promise(resolve => setTimeout(resolve, retryInterval)); - + + const errorMsg = response && (response.message || response.msg) ? (response.message || response.msg) : '未知错误'; + throw new Error(`剪辑计划生成失败: ${errorMsg}`); } catch (error) { - if (attempts >= maxAttempts) { + if (attempt < maxAttempts) { + this.log(`项目 ${projectId}: 获取剪辑计划失败(第${attempt}次)- ${error.message},${Math.round(retryDelayMs/1000)}秒后重试...`, 'warn'); + await new Promise(resolve => setTimeout(resolve, retryDelayMs)); + } else { + // 第3次仍失败,直接抛出,终止该项目后续导出 throw new Error(`获取剪辑计划失败,已重试${maxAttempts}次: ${error.message}`); } - - this.log(`项目 ${projectId}: 第${attempts}次尝试出现错误: ${error.message}`); - await new Promise(resolve => setTimeout(resolve, retryInterval)); } } - - throw new Error(`获取剪辑计划超时,已重试${maxAttempts}次`); + + // 理论上不会到达这里 + throw new Error(`获取剪辑计划失败`); } /** 解析时间码为毫秒 */