fix: conform route broken SQL — remove dead DB insert, use BullMQ directly
The POST /conform route was inserting into the jobs table with non-existent
columns (project_id, metadata) and an invalid enum value ('pending'). Since
GET /jobs reads entirely from BullMQ, the DB insert was both incorrect and
redundant. Now we just enqueue the BullMQ job and return its ID.
This commit is contained in:
parent
596f755a6c
commit
48b69879cb
1 changed files with 13 additions and 25 deletions
|
|
@ -2,7 +2,6 @@ import express from 'express';
|
|||
import pool from '../db/pool.js';
|
||||
import { requireAuth } from '../middleware/auth.js';
|
||||
import { Queue } from 'bullmq';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const router = express.Router();
|
||||
router.use(requireAuth);
|
||||
|
|
@ -60,16 +59,17 @@ function normalizeJob(bullJob, type, apiStatus) {
|
|||
|
||||
async function getAllBullMQJobs() {
|
||||
const results = [];
|
||||
const allStates = ['waiting', 'active', 'completed', 'failed', 'delayed', 'paused'];
|
||||
for (const { queue, type } of QUEUES) {
|
||||
for (const [bullState, apiStatus] of Object.entries(STATE_MAP)) {
|
||||
try {
|
||||
const jobs = await queue.getJobs([bullState], 0, 200);
|
||||
for (const job of jobs) {
|
||||
results.push(normalizeJob(job, type, apiStatus));
|
||||
}
|
||||
} catch {
|
||||
// queue may be empty or unavailable for this state – skip
|
||||
try {
|
||||
const jobs = await queue.getJobs(allStates, 0, 200);
|
||||
for (const job of jobs) {
|
||||
const state = await job.getState();
|
||||
const apiStatus = STATE_MAP[state] || state;
|
||||
results.push(normalizeJob(job, type, apiStatus));
|
||||
}
|
||||
} catch {
|
||||
// queue may be unavailable – skip
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
|
@ -142,7 +142,7 @@ router.delete('/:id', async (req, res, next) => {
|
|||
}
|
||||
});
|
||||
|
||||
// ── POST /conform - Submit a conform job ──────────────────────────────────────
|
||||
// ── POST /conform - Submit a conform (EDL export) job ────────────────────────
|
||||
router.post('/conform', async (req, res, next) => {
|
||||
try {
|
||||
const { edl, project_id, output_format } = req.body;
|
||||
|
|
@ -153,25 +153,13 @@ router.post('/conform', async (req, res, next) => {
|
|||
});
|
||||
}
|
||||
|
||||
const jobId = uuidv4();
|
||||
|
||||
const result = await pool.query(
|
||||
`INSERT INTO jobs (id, type, status, project_id, metadata, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, NOW(), NOW())
|
||||
RETURNING *`,
|
||||
[jobId, 'conform', 'pending', project_id, JSON.stringify({ edl, output_format })]
|
||||
);
|
||||
|
||||
const job = result.rows[0];
|
||||
|
||||
await conformQueue.add('conform-task', {
|
||||
jobId,
|
||||
const bullJob = await conformQueue.add('conform-task', {
|
||||
edl,
|
||||
projectId: project_id,
|
||||
projectId: project_id,
|
||||
outputFormat: output_format,
|
||||
});
|
||||
|
||||
res.status(201).json(job);
|
||||
res.status(202).json({ id: `conform:${bullJob.id}`, status: 'queued' });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue