Wire the app, worker, and cleanup entry points onto Prisma Client
Task 4 rewrote src/db.js and src/jobs/jobRepository.js to use Prisma instead of the hand-rolled mariadb pool. This updates every remaining call site (app.js, server.js, worker.js, cleanup.js) and the 5 test files that still referenced getPool/closePool/pool.query, so the app and full test suite compile and run against Prisma Client. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+13
-13
@@ -1,7 +1,7 @@
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import fs from 'node:fs/promises';
|
||||
import { loadConfig } from './config.js';
|
||||
import { getPool } from './db.js';
|
||||
import { getPrismaClient } from './db.js';
|
||||
import { ensureStorageDirs, uploadPath, outputPath, deleteIfExists } from './storage.js';
|
||||
import { outputMimeType } from './mime.js';
|
||||
import { resolve as resolveConverter } from './converters/registry.js';
|
||||
@@ -20,8 +20,8 @@ function withTimeout(promise, ms) {
|
||||
return Promise.race([promise, timeout]).finally(() => clearTimeout(timeoutId));
|
||||
}
|
||||
|
||||
async function processJob(pool, config, job) {
|
||||
await markProcessing(pool, job.id);
|
||||
async function processJob(prisma, config, job) {
|
||||
await markProcessing(prisma, job.id);
|
||||
|
||||
const inputFilePath = uploadPath(config, job.uuid, job.sourceFormat);
|
||||
const outputFilePath = outputPath(config, job.uuid, job.targetFormat);
|
||||
@@ -37,7 +37,7 @@ async function processJob(pool, config, job) {
|
||||
const conversionDurationSeconds = (Date.now() - startedAt) / 1000;
|
||||
const { size: outputSizeBytes } = await fs.stat(outputFilePath);
|
||||
|
||||
await markDone(pool, job.id, {
|
||||
await markDone(prisma, job.id, {
|
||||
outputPath: `${job.uuid}.${job.targetFormat}`,
|
||||
outputMimeType: outputMimeType(job.targetFormat),
|
||||
outputSizeBytes,
|
||||
@@ -45,22 +45,22 @@ async function processJob(pool, config, job) {
|
||||
});
|
||||
} catch (error) {
|
||||
await deleteIfExists(outputFilePath);
|
||||
await markFailed(pool, job.id, {
|
||||
await markFailed(prisma, job.id, {
|
||||
errorMessage: 'Conversion failed, please try again.',
|
||||
errorLog: error.stack ?? String(error),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function processPendingJobs(pool, config) {
|
||||
const jobs = await findPendingJobs(pool, config.workerConcurrency);
|
||||
await Promise.all(jobs.map((job) => processJob(pool, config, job)));
|
||||
export async function processPendingJobs(prisma, config) {
|
||||
const jobs = await findPendingJobs(prisma, config.workerConcurrency);
|
||||
await Promise.all(jobs.map((job) => processJob(prisma, config, job)));
|
||||
return jobs.length;
|
||||
}
|
||||
|
||||
export function startWorker(pool, config) {
|
||||
export function startWorker(prisma, config) {
|
||||
const interval = setInterval(() => {
|
||||
processPendingJobs(pool, config).catch((error) => {
|
||||
processPendingJobs(prisma, config).catch((error) => {
|
||||
console.error('Error while processing pending jobs:', error);
|
||||
});
|
||||
}, config.workerPollIntervalMs);
|
||||
@@ -70,14 +70,14 @@ export function startWorker(pool, config) {
|
||||
async function main() {
|
||||
const config = loadConfig();
|
||||
await ensureStorageDirs(config);
|
||||
const pool = getPool(config);
|
||||
const prisma = getPrismaClient(config);
|
||||
|
||||
registerImageConverters();
|
||||
registerImageToPdfConverter();
|
||||
registerDocumentConverters();
|
||||
|
||||
startWorker(pool, config);
|
||||
startWorker(prisma, config);
|
||||
console.log(`Worker started, polling every ${config.workerPollIntervalMs}ms`);
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user