tts: remove redundant route-level alignment timeout wrappers
This commit is contained in:
parent
c9dad9c23c
commit
3c25c93e8b
1 changed files with 8 additions and 32 deletions
|
|
@ -35,7 +35,6 @@ import { getCompute } from '@/lib/server/compute';
|
||||||
import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config';
|
import { getResolvedRuntimeConfig } from '@/lib/server/runtime-config';
|
||||||
import { resolveTtsModelForProvider } from '@/lib/shared/tts-provider-policy';
|
import { resolveTtsModelForProvider } from '@/lib/shared/tts-provider-policy';
|
||||||
import { resolveSegmentAudioUrls } from '@/lib/server/tts/segment-audio-urls';
|
import { resolveSegmentAudioUrls } from '@/lib/server/tts/segment-audio-urls';
|
||||||
import { getComputeTimeoutConfig } from '@openreader/compute-core/runtime/timeout-config';
|
|
||||||
import type {
|
import type {
|
||||||
TTSSegmentInput,
|
TTSSegmentInput,
|
||||||
TTSSegmentManifestItem,
|
TTSSegmentManifestItem,
|
||||||
|
|
@ -46,7 +45,6 @@ import type {
|
||||||
export const runtime = 'nodejs';
|
export const runtime = 'nodejs';
|
||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
const GENERATING_STALE_MS = 360_000;
|
const GENERATING_STALE_MS = 360_000;
|
||||||
const SHARED_ALIGNMENT_TIMEOUT_MS = getComputeTimeoutConfig().whisperTimeoutMs;
|
|
||||||
|
|
||||||
function attachDeviceIdCookie(response: NextResponse, deviceId: string | null, didCreate: boolean) {
|
function attachDeviceIdCookie(response: NextResponse, deviceId: string | null, didCreate: boolean) {
|
||||||
if (didCreate && deviceId) {
|
if (didCreate && deviceId) {
|
||||||
|
|
@ -131,20 +129,6 @@ function isAbortLikeError(error: unknown): boolean {
|
||||||
return /abort/i.test(message);
|
return /abort/i.test(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function withTimeout<T>(promise: Promise<T>, timeoutMs: number, label: string): Promise<T> {
|
|
||||||
let timer: NodeJS.Timeout | null = null;
|
|
||||||
try {
|
|
||||||
return await Promise.race([
|
|
||||||
promise,
|
|
||||||
new Promise<T>((_, reject) => {
|
|
||||||
timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
} finally {
|
|
||||||
if (timer) clearTimeout(timer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteEntryIfUnused(userId: string, segmentEntryId: string): Promise<void> {
|
async function deleteEntryIfUnused(userId: string, segmentEntryId: string): Promise<void> {
|
||||||
const stillReferenced = await db
|
const stillReferenced = await db
|
||||||
.select({ segmentId: ttsSegmentVariants.segmentId })
|
.select({ segmentId: ttsSegmentVariants.segmentId })
|
||||||
|
|
@ -402,14 +386,10 @@ export async function POST(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const alignStartedAt = Date.now();
|
const alignStartedAt = Date.now();
|
||||||
const computeBackend = await getComputeBackend();
|
const computeBackend = await getComputeBackend();
|
||||||
const aligned = (await withTimeout(
|
const aligned = (await computeBackend.alignWords({
|
||||||
computeBackend.alignWords({
|
audioObjectKey: existing.audioKey,
|
||||||
audioObjectKey: existing.audioKey,
|
text: segment.text,
|
||||||
text: segment.text,
|
})).alignments;
|
||||||
}),
|
|
||||||
SHARED_ALIGNMENT_TIMEOUT_MS,
|
|
||||||
`Whisper alignment (${computeBackend.mode})`,
|
|
||||||
)).alignments;
|
|
||||||
stageTimings.selfHealAlignMs = Date.now() - alignStartedAt;
|
stageTimings.selfHealAlignMs = Date.now() - alignStartedAt;
|
||||||
alignment = aligned[0] ? { ...aligned[0], sentenceIndex: segment.original.segmentIndex } : null;
|
alignment = aligned[0] ? { ...aligned[0], sentenceIndex: segment.original.segmentIndex } : null;
|
||||||
|
|
||||||
|
|
@ -656,14 +636,10 @@ export async function POST(request: NextRequest) {
|
||||||
failedStage = 'whisper.align';
|
failedStage = 'whisper.align';
|
||||||
const alignStartedAt = Date.now();
|
const alignStartedAt = Date.now();
|
||||||
const computeBackend = await getComputeBackend();
|
const computeBackend = await getComputeBackend();
|
||||||
const aligned = (await withTimeout(
|
const aligned = (await computeBackend.alignWords({
|
||||||
computeBackend.alignWords({
|
audioObjectKey: audioKey,
|
||||||
audioObjectKey: audioKey,
|
text: segment.text,
|
||||||
text: segment.text,
|
})).alignments;
|
||||||
}),
|
|
||||||
SHARED_ALIGNMENT_TIMEOUT_MS,
|
|
||||||
`Whisper alignment (${computeBackend.mode})`,
|
|
||||||
)).alignments;
|
|
||||||
stageTimings.whisperAlignMs = Date.now() - alignStartedAt;
|
stageTimings.whisperAlignMs = Date.now() - alignStartedAt;
|
||||||
alignment = aligned[0] ? { ...aligned[0], sentenceIndex: segment.original.segmentIndex } : null;
|
alignment = aligned[0] ? { ...aligned[0], sentenceIndex: segment.original.segmentIndex } : null;
|
||||||
} catch (alignError) {
|
} catch (alignError) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue