Skip to content

Commit eac163c

Browse files
committed
update more callsites
1 parent b53ed5d commit eac163c

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

apps/sim/app/api/tools/stt/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { extractAudioFromVideo, isVideoFile } from '@/lib/audio/extractor'
44
import { checkInternalAuth } from '@/lib/auth/hybrid'
5+
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
56
import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server'
67
import type { UserFile } from '@/executor/types'
78
import type { TranscriptSegment } from '@/tools/stt/types'
@@ -568,7 +569,8 @@ async function transcribeWithAssemblyAI(
568569

569570
let transcript: any
570571
let attempts = 0
571-
const maxAttempts = 60 // 5 minutes with 5-second intervals
572+
const pollIntervalMs = 5000
573+
const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs)
572574

573575
while (attempts < maxAttempts) {
574576
const statusResponse = await fetch(`https://api.assemblyai.com/v2/transcript/${id}`, {

apps/sim/app/api/tools/textract/parse/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createLogger } from '@sim/logger'
33
import { type NextRequest, NextResponse } from 'next/server'
44
import { z } from 'zod'
55
import { checkInternalAuth } from '@/lib/auth/hybrid'
6+
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
67
import {
78
validateAwsRegion,
89
validateExternalUrl,
@@ -205,8 +206,8 @@ async function pollForJobCompletion(
205206
useAnalyzeDocument: boolean,
206207
requestId: string
207208
): Promise<Record<string, unknown>> {
208-
const pollIntervalMs = 5000 // 5 seconds between polls
209-
const maxPollTimeMs = 180000 // 3 minutes maximum polling time
209+
const pollIntervalMs = 5000
210+
const maxPollTimeMs = DEFAULT_EXECUTION_TIMEOUT_MS
210211
const maxAttempts = Math.ceil(maxPollTimeMs / pollIntervalMs)
211212

212213
const getTarget = useAnalyzeDocument

apps/sim/app/api/tools/tts/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import type { NextRequest } from 'next/server'
33
import { NextResponse } from 'next/server'
44
import { checkInternalAuth } from '@/lib/auth/hybrid'
5+
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
56
import { validateAlphanumericId } from '@/lib/core/security/input-validation'
67
import { getBaseUrl } from '@/lib/core/utils/urls'
78
import { StorageService } from '@/lib/uploads'
@@ -60,7 +61,7 @@ export async function POST(request: NextRequest) {
6061
text,
6162
model_id: modelId,
6263
}),
63-
signal: AbortSignal.timeout(60000),
64+
signal: AbortSignal.timeout(DEFAULT_EXECUTION_TIMEOUT_MS),
6465
})
6566

6667
if (!response.ok) {

apps/sim/app/api/tools/video/route.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { checkInternalAuth } from '@/lib/auth/hybrid'
4+
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
45
import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server'
56
import type { UserFile } from '@/executor/types'
67
import type { VideoRequestBody } from '@/tools/video/types'
@@ -326,11 +327,12 @@ async function generateWithRunway(
326327

327328
logger.info(`[${requestId}] Runway task created: ${taskId}`)
328329

329-
const maxAttempts = 120 // 10 minutes with 5-second intervals
330+
const pollIntervalMs = 5000
331+
const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs)
330332
let attempts = 0
331333

332334
while (attempts < maxAttempts) {
333-
await sleep(5000) // Poll every 5 seconds
335+
await sleep(pollIntervalMs)
334336

335337
const statusResponse = await fetch(`https://api.dev.runwayml.com/v1/tasks/${taskId}`, {
336338
headers: {
@@ -429,11 +431,12 @@ async function generateWithVeo(
429431

430432
logger.info(`[${requestId}] Veo operation created: ${operationName}`)
431433

432-
const maxAttempts = 60 // 5 minutes with 5-second intervals
434+
const pollIntervalMs = 5000
435+
const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs)
433436
let attempts = 0
434437

435438
while (attempts < maxAttempts) {
436-
await sleep(5000)
439+
await sleep(pollIntervalMs)
437440

438441
const statusResponse = await fetch(
439442
`https://generativelanguage.googleapis.com/v1beta/${operationName}`,
@@ -541,11 +544,12 @@ async function generateWithLuma(
541544

542545
logger.info(`[${requestId}] Luma generation created: ${generationId}`)
543546

544-
const maxAttempts = 120 // 10 minutes
547+
const pollIntervalMs = 5000
548+
const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs)
545549
let attempts = 0
546550

547551
while (attempts < maxAttempts) {
548-
await sleep(5000)
552+
await sleep(pollIntervalMs)
549553

550554
const statusResponse = await fetch(
551555
`https://api.lumalabs.ai/dream-machine/v1/generations/${generationId}`,
@@ -658,14 +662,13 @@ async function generateWithMiniMax(
658662

659663
logger.info(`[${requestId}] MiniMax task created: ${taskId}`)
660664

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)
663667
let attempts = 0
664668

665669
while (attempts < maxAttempts) {
666-
await sleep(5000)
670+
await sleep(pollIntervalMs)
667671

668-
// Query task status
669672
const statusResponse = await fetch(
670673
`https://api.minimax.io/v1/query/video_generation?task_id=${taskId}`,
671674
{
@@ -861,11 +864,12 @@ async function generateWithFalAI(
861864
// Get base model ID (without subpath) for status and result endpoints
862865
const baseModelId = getBaseModelId(falModelId)
863866

864-
const maxAttempts = 96 // 8 minutes with 5-second intervals
867+
const pollIntervalMs = 5000
868+
const maxAttempts = Math.ceil(DEFAULT_EXECUTION_TIMEOUT_MS / pollIntervalMs)
865869
let attempts = 0
866870

867871
while (attempts < maxAttempts) {
868-
await sleep(5000)
872+
await sleep(pollIntervalMs)
869873

870874
const statusResponse = await fetch(
871875
`https://queue.fal.run/${baseModelId}/requests/${requestIdFal}/status`,

apps/sim/lib/core/idempotency/service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { idempotencyKey } from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
55
import { eq } from 'drizzle-orm'
66
import { getRedisClient } from '@/lib/core/config/redis'
7+
import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
78
import { getStorageMethod, type StorageMethod } from '@/lib/core/storage'
89
import { extractProviderIdentifierFromBody } from '@/lib/webhooks/provider-utils'
910

@@ -36,9 +37,9 @@ export interface AtomicClaimResult {
3637
storageMethod: StorageMethod
3738
}
3839

39-
const DEFAULT_TTL = 60 * 60 * 24 * 7 // 7 days
40+
const DEFAULT_TTL = 60 * 60 * 24 * 7
4041
const REDIS_KEY_PREFIX = 'idempotency:'
41-
const MAX_WAIT_TIME_MS = 300000 // 5 minutes max wait
42+
const MAX_WAIT_TIME_MS = getMaxExecutionTimeout()
4243
const POLL_INTERVAL_MS = 1000
4344

4445
/**

apps/sim/lib/core/security/input-validation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import https from 'https'
44
import type { LookupFunction } from 'net'
55
import { createLogger } from '@sim/logger'
66
import * as ipaddr from 'ipaddr.js'
7+
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
78

89
const logger = createLogger('InputValidation')
910

@@ -931,7 +932,7 @@ export async function secureFetchWithPinnedIP(
931932
method: options.method || 'GET',
932933
headers: sanitizedHeaders,
933934
agent,
934-
timeout: options.timeout || 300000, // Default 5 minutes
935+
timeout: options.timeout || DEFAULT_EXECUTION_TIMEOUT_MS,
935936
}
936937

937938
const protocol = isHttps ? https : http

0 commit comments

Comments
 (0)