|
1 | 1 | import { createLogger } from '@sim/logger' |
2 | 2 | import { type NextRequest, NextResponse } from 'next/server' |
3 | 3 | import { checkInternalAuth } from '@/lib/auth/hybrid' |
| 4 | +import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits' |
4 | 5 | import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server' |
5 | 6 | import type { UserFile } from '@/executor/types' |
6 | 7 | import type { VideoRequestBody } from '@/tools/video/types' |
@@ -326,11 +327,12 @@ async function generateWithRunway( |
326 | 327 |
|
327 | 328 | logger.info(`[${requestId}] Runway task created: ${taskId}`) |
328 | 329 |
|
329 | | - const maxAttempts = 120 // 10 minutes with 5-second intervals |
| 330 | + const pollIntervalMs = 5000 |
| 331 | + const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs) |
330 | 332 | let attempts = 0 |
331 | 333 |
|
332 | 334 | while (attempts < maxAttempts) { |
333 | | - await sleep(5000) // Poll every 5 seconds |
| 335 | + await sleep(pollIntervalMs) |
334 | 336 |
|
335 | 337 | const statusResponse = await fetch(`https://api.dev.runwayml.com/v1/tasks/${taskId}`, { |
336 | 338 | headers: { |
@@ -429,11 +431,12 @@ async function generateWithVeo( |
429 | 431 |
|
430 | 432 | logger.info(`[${requestId}] Veo operation created: ${operationName}`) |
431 | 433 |
|
432 | | - const maxAttempts = 60 // 5 minutes with 5-second intervals |
| 434 | + const pollIntervalMs = 5000 |
| 435 | + const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs) |
433 | 436 | let attempts = 0 |
434 | 437 |
|
435 | 438 | while (attempts < maxAttempts) { |
436 | | - await sleep(5000) |
| 439 | + await sleep(pollIntervalMs) |
437 | 440 |
|
438 | 441 | const statusResponse = await fetch( |
439 | 442 | `https://generativelanguage.googleapis.com/v1beta/${operationName}`, |
@@ -541,11 +544,12 @@ async function generateWithLuma( |
541 | 544 |
|
542 | 545 | logger.info(`[${requestId}] Luma generation created: ${generationId}`) |
543 | 546 |
|
544 | | - const maxAttempts = 120 // 10 minutes |
| 547 | + const pollIntervalMs = 5000 |
| 548 | + const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs) |
545 | 549 | let attempts = 0 |
546 | 550 |
|
547 | 551 | while (attempts < maxAttempts) { |
548 | | - await sleep(5000) |
| 552 | + await sleep(pollIntervalMs) |
549 | 553 |
|
550 | 554 | const statusResponse = await fetch( |
551 | 555 | `https://api.lumalabs.ai/dream-machine/v1/generations/${generationId}`, |
@@ -658,14 +662,13 @@ async function generateWithMiniMax( |
658 | 662 |
|
659 | 663 | logger.info(`[${requestId}] MiniMax task created: ${taskId}`) |
660 | 664 |
|
661 | | - // Poll for completion (6-10 minutes typical) |
662 | | - const maxAttempts = 120 // 10 minutes with 5-second intervals |
| 665 | + const pollIntervalMs = 5000 |
| 666 | + const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs) |
663 | 667 | let attempts = 0 |
664 | 668 |
|
665 | 669 | while (attempts < maxAttempts) { |
666 | | - await sleep(5000) |
| 670 | + await sleep(pollIntervalMs) |
667 | 671 |
|
668 | | - // Query task status |
669 | 672 | const statusResponse = await fetch( |
670 | 673 | `https://api.minimax.io/v1/query/video_generation?task_id=${taskId}`, |
671 | 674 | { |
@@ -861,11 +864,12 @@ async function generateWithFalAI( |
861 | 864 | // Get base model ID (without subpath) for status and result endpoints |
862 | 865 | const baseModelId = getBaseModelId(falModelId) |
863 | 866 |
|
864 | | - const maxAttempts = 96 // 8 minutes with 5-second intervals |
| 867 | + const pollIntervalMs = 5000 |
| 868 | + const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs) |
865 | 869 | let attempts = 0 |
866 | 870 |
|
867 | 871 | while (attempts < maxAttempts) { |
868 | | - await sleep(5000) |
| 872 | + await sleep(pollIntervalMs) |
869 | 873 |
|
870 | 874 | const statusResponse = await fetch( |
871 | 875 | `https://queue.fal.run/${baseModelId}/requests/${requestIdFal}/status`, |
|
0 commit comments