D3: Wire health preflight into pipeline before whisper submission
- Add health preflight gate after ensureWhisperRunning, before submitJob - Uses getHealth() (existing) + retryWithBackoff for transient failures - Network errors wrapped with 'whisper health check failed:' prefix - Non-ok status fails job early with actual status in error message - Revert compose.yaml 'name: tonemark' removal (out of scope change) - Restore health-preflight.test.ts (228-line test covering all ACs) - 8 test cases, 202 total tests passing, typecheck clean, build OK
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { createJob, updateJob, setJobStatus, getJob, resetJob } from './db.js';
|
||||
import { downloadYouTube, saveUploadedFile, cleanupJobTmp, getUploadPath, cleanupUploadDir } from './downloader.js';
|
||||
import { prepareAudio, cleanup as cleanupFiles } from './audio.js';
|
||||
import { submitJob, streamJob } from './whisper.js';
|
||||
import { submitJob, streamJob, getHealth } from './whisper.js';
|
||||
import { retryWithBackoff } from './retry.js';
|
||||
import { ensureWhisperRunning } from './docker.js';
|
||||
import type { AudioMode, Segment } from '$lib/types.js';
|
||||
|
||||
@@ -151,6 +152,30 @@ async function runJob(
|
||||
// ── 3. Ensure whisper is running ──────────────────────────────────────
|
||||
await ensureWhisperRunning();
|
||||
|
||||
// ── 3b. Health preflight ────────────────────────────────────────────
|
||||
try {
|
||||
await retryWithBackoff(
|
||||
async () => {
|
||||
const health = await getHealth();
|
||||
if (health.status !== 'ok') {
|
||||
throw new Error(`whisper health check failed: whisper status is "${health.status}"`);
|
||||
}
|
||||
},
|
||||
{
|
||||
maxAttempts: 2,
|
||||
baseDelayMs: 1000,
|
||||
onAttempt: (err, attempt, ms) =>
|
||||
console.warn(`[pipeline] health check attempt ${attempt} failed, retry in ${ms}ms:`, err)
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
if (!msg.startsWith('whisper health check failed:')) {
|
||||
throw new Error(`whisper health check failed: ${msg}`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
// ── 4. Submit to whisper with webhook ────────────────────────────────
|
||||
setJobStatus(jobId, 'transcribing', 10);
|
||||
emitProgress(jobId, { type: 'status', status: 'transcribing', progress: 10 });
|
||||
|
||||
Reference in New Issue
Block a user