forked from 77media/video-flow
剪辑计划失败最多调用三次
This commit is contained in:
parent
8cc118b460
commit
265fb1e08c
@ -92,18 +92,12 @@ class BatchVideoExporter {
|
|||||||
/** 生成剪辑计划 */
|
/** 生成剪辑计划 */
|
||||||
async generateEditPlan(projectId) {
|
async generateEditPlan(projectId) {
|
||||||
this.log(`开始为项目 ${projectId} 生成剪辑计划...`);
|
this.log(`开始为项目 ${projectId} 生成剪辑计划...`);
|
||||||
|
const maxAttempts = 3; // 最多重试3次
|
||||||
|
const retryDelayMs = Number(this.config.retryDelay || 3000);
|
||||||
|
|
||||||
const maxRetryTime = 10 * 60 * 1000; // 10分钟
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||||
const retryInterval = 8 * 1000; // 8秒
|
|
||||||
const maxAttempts = Math.floor(maxRetryTime / retryInterval);
|
|
||||||
|
|
||||||
let attempts = 0;
|
|
||||||
|
|
||||||
while (attempts < maxAttempts) {
|
|
||||||
attempts++;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.log(`项目 ${projectId}: 第${attempts}次尝试获取剪辑计划...`);
|
this.log(`项目 ${projectId}: 第${attempt}次尝试获取剪辑计划...`);
|
||||||
|
|
||||||
const response = await this.makeRequest('/edit-plan/generate-by-project', {
|
const response = await this.makeRequest('/edit-plan/generate-by-project', {
|
||||||
project_id: projectId
|
project_id: projectId
|
||||||
@ -114,24 +108,21 @@ class BatchVideoExporter {
|
|||||||
return response.data.editing_plan;
|
return response.data.editing_plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attempts >= maxAttempts) {
|
const errorMsg = response && (response.message || response.msg) ? (response.message || response.msg) : '未知错误';
|
||||||
throw new Error(`剪辑计划生成失败: ${response.message || '未知错误'}`);
|
throw new Error(`剪辑计划生成失败: ${errorMsg}`);
|
||||||
}
|
|
||||||
|
|
||||||
this.log(`项目 ${projectId}: 第${attempts}次尝试失败,${retryInterval/1000}秒后重试...`);
|
|
||||||
await new Promise(resolve => setTimeout(resolve, retryInterval));
|
|
||||||
|
|
||||||
} catch (error) {
|
} 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}`);
|
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(`获取剪辑计划失败`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 解析时间码为毫秒 */
|
/** 解析时间码为毫秒 */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user