ly0303521

添加视频生成状态超时处理,限制处理时间为8分钟

... ... @@ -36,6 +36,9 @@ export const pollVideoStatus = (
onStatusUpdate: (status: VideoStatus) => void
): Promise<VideoStatus> => {
return new Promise((resolve, reject) => {
let processingStartTime: number | null = null;
const PROCESSING_TIMEOUT_MS = 8 * 60 * 1000; // 8 minutes limit for processing
const interval = setInterval(async () => {
try {
const res = await fetch(`${TURBO_DIFFUSION_API_URL}/status/${taskId}`);
... ... @@ -49,6 +52,17 @@ export const pollVideoStatus = (
const data: VideoStatus = await res.json();
onStatusUpdate(data);
// Track processing time
if (data.status === 'processing') {
if (processingStartTime === null) {
processingStartTime = Date.now();
} else if (Date.now() - processingStartTime > PROCESSING_TIMEOUT_MS) {
clearInterval(interval);
reject(new Error("Video generation timed out (8 minutes processing limit)."));
return;
}
}
if (data.status === 'complete' || data.status === 'failed') {
clearInterval(interval);
if (data.status === 'failed') {
... ... @@ -58,9 +72,8 @@ export const pollVideoStatus = (
}
}
} catch (error) {
clearInterval(interval);
console.error('Polling error:', error);
reject(error);
// Don't stop polling on transient network errors
console.warn('Polling transient error:', error);
}
}, 2000); // Poll every 2 seconds
});
... ...