feat: add auto-increment id, size/duration tracking, and soft cleanup to conversion_jobs
Rename the old CHAR(36) id to uuid (still used for public URLs and file naming) and add a real auto-increment id as the primary key. Track input/output file size and conversion duration per job. Cleanup no longer deletes rows; it marks cleaned_at and skips already-cleaned expired jobs on later runs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+9
-3
@@ -1,4 +1,5 @@
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import fs from 'node:fs/promises';
|
||||
import { loadConfig } from './config.js';
|
||||
import { getPool } from './db.js';
|
||||
import { ensureStorageDirs, uploadPath, outputPath, deleteIfExists } from './storage.js';
|
||||
@@ -22,8 +23,8 @@ function withTimeout(promise, ms) {
|
||||
async function processJob(pool, config, job) {
|
||||
await markProcessing(pool, job.id);
|
||||
|
||||
const inputFilePath = uploadPath(config, job.id, job.sourceFormat);
|
||||
const outputFilePath = outputPath(config, job.id, job.targetFormat);
|
||||
const inputFilePath = uploadPath(config, job.uuid, job.sourceFormat);
|
||||
const outputFilePath = outputPath(config, job.uuid, job.targetFormat);
|
||||
|
||||
try {
|
||||
const entry = resolveConverter(job.sourceFormat, job.targetFormat);
|
||||
@@ -31,11 +32,16 @@ async function processJob(pool, config, job) {
|
||||
throw new Error(`No converter registered for ${job.sourceFormat} -> ${job.targetFormat}`);
|
||||
}
|
||||
|
||||
const startedAt = Date.now();
|
||||
await withTimeout(entry.convert(inputFilePath, outputFilePath), JOB_TIMEOUT_MS);
|
||||
const conversionDurationSeconds = (Date.now() - startedAt) / 1000;
|
||||
const { size: outputSizeBytes } = await fs.stat(outputFilePath);
|
||||
|
||||
await markDone(pool, job.id, {
|
||||
outputPath: `${job.id}.${job.targetFormat}`,
|
||||
outputPath: `${job.uuid}.${job.targetFormat}`,
|
||||
outputMimeType: outputMimeType(job.targetFormat),
|
||||
outputSizeBytes,
|
||||
conversionDurationSeconds,
|
||||
});
|
||||
} catch (error) {
|
||||
await deleteIfExists(outputFilePath);
|
||||
|
||||
Reference in New Issue
Block a user