diff --git a/services/worker/src/workers/conform.js b/services/worker/src/workers/conform.js index 7de74b1..c9cf93b 100644 --- a/services/worker/src/workers/conform.js +++ b/services/worker/src/workers/conform.js @@ -9,13 +9,14 @@ import { parseEDL } from '../edl/parser.js'; const S3_BUCKET = process.env.S3_BUCKET || 'wild-dragon'; export const conformWorker = async (job) => { - const { jobId, edl, projectId, outputFormat } = job.data; + const { edl, projectId, outputFormat } = job.data; + const jobId = job.id; const tmpDir = tmpdir(); - const edlPath = join(tmpDir, `edl-${job.id}.edl`); - const segmentsDir = join(tmpDir, `segments-${job.id}`); - const segmentListPath = join(tmpDir, `segments-${job.id}.txt`); - const outputPath = join(tmpDir, `output-${job.id}.${outputFormat || 'mov'}`); + const edlPath = join(tmpDir, `edl-${jobId}.edl`); + const segmentsDir = join(tmpDir, `segments-${jobId}`); + const segmentListPath = join(tmpDir, `segments-${jobId}.txt`); + const outputPath = join(tmpDir, `output-${jobId}.${outputFormat || 'mov'}`); try { // Write EDL to temp file @@ -47,7 +48,7 @@ export const conformWorker = async (job) => { throw new Error(`Asset not found for reel: ${edit.reelName}`); } - const { id: assetId, original_s3_key: sourceKey } = assetRes.rows[0]; + const { original_s3_key: sourceKey } = assetRes.rows[0]; const segmentInputPath = join(segmentsDir, `segment-${edit.editNumber}-src`); const segmentOutputPath = join(segmentsDir, `segment-${edit.editNumber}.mov`); @@ -84,23 +85,15 @@ export const conformWorker = async (job) => { console.log(`[conform] Uploading output to ${outputKey}`); await uploadToS3(S3_BUCKET, outputKey, outputPath); - // Mark job complete - await job.updateProgress(95); - await query( - `UPDATE jobs SET status = 'complete', result = $1, updated_at = NOW() WHERE id = $2`, - [JSON.stringify({ output_key: outputKey }), jobId] - ); - await job.updateProgress(100); - console.log(`[conform] Job ${jobId} complete`); + console.log(`[conform] Job ${jobId} complete → ${outputKey}`); + + // Return value is stored by BullMQ and visible via GET /api/v1/jobs/:id return { jobId, outputKey }; } catch (error) { console.error(`[conform] Error in job ${jobId}:`, error); - await query( - `UPDATE jobs SET status = 'failed', error = $1, updated_at = NOW() WHERE id = $2`, - [error.message, jobId] - ); + // BullMQ marks the job failed automatically when we throw throw error; } finally {