Refactor queue. Still only processing 1 job.
This commit is contained in:
@@ -1,45 +1,45 @@
|
||||
import { SandboxedJob } from "bullmq";
|
||||
import { logger } from "../server.js";
|
||||
import dotenv from "dotenv";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import { FolderPaths } from "./serverInit.js";
|
||||
import gm from "gm";
|
||||
const imageMagick = gm.subClass({ imageMagick: true });
|
||||
export default async function (job: SandboxedJob) {
|
||||
// Do something with job
|
||||
console.log("*** We're in the processing Queue")
|
||||
const { file, convertedFileName } = job.data;
|
||||
try {
|
||||
logger.log("debug", `Attempting to convert ${file.filename} image to JPEG from HEIC.`);
|
||||
await ConvertToJpeg(file.path, `${file.destination}/${convertedFileName}`);
|
||||
logger.log("debug", `Converted ${file.filename} image to JPEG from HEIC.`);
|
||||
await handleOriginalFile(file, convertedFileName);
|
||||
file.filename = convertedFileName;
|
||||
file.mimetype = "image/jpeg";
|
||||
file.path = `${file.destination}/${convertedFileName}`;
|
||||
} catch (error) {
|
||||
logger.log("error", `Error converting ${file.filename} image to JPEG from HEIC. ${JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
async function handleOriginalFile(file: Express.Multer.File, convertedFileName: string) {
|
||||
if (process.env.KEEP_CONVERTED_ORIGINALS) {
|
||||
await fs.ensureDir(path.join(file.destination, FolderPaths.ConvertedOriginalSubDir));
|
||||
await fs.move(file.path, `${path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)}/${file.filename}`);
|
||||
} else {
|
||||
await fs.unlink(file.path);
|
||||
}
|
||||
}
|
||||
// import { SandboxedJob } from "bullmq";
|
||||
// import { logger } from "../server.js";
|
||||
// import dotenv from "dotenv";
|
||||
// import fs from "fs-extra";
|
||||
// import path from "path";
|
||||
// import { FolderPaths } from "./serverInit.js";
|
||||
// import gm from "gm";
|
||||
// const imageMagick = gm.subClass({ imageMagick: true });
|
||||
// export default async function (job: SandboxedJob) {
|
||||
// // Do something with job
|
||||
// console.log("*** We're in the processing Queue")
|
||||
// const { file, convertedFileName } = job.data;
|
||||
// try {
|
||||
// logger.log("debug", `Attempting to convert ${file.filename} image to JPEG from HEIC.`);
|
||||
// await ConvertToJpeg(file.path, `${file.destination}/${convertedFileName}`);
|
||||
// logger.log("debug", `Converted ${file.filename} image to JPEG from HEIC.`);
|
||||
// await handleOriginalFile(file, convertedFileName);
|
||||
// file.filename = convertedFileName;
|
||||
// file.mimetype = "image/jpeg";
|
||||
// file.path = `${file.destination}/${convertedFileName}`;
|
||||
// } catch (error) {
|
||||
// logger.log("error", `Error converting ${file.filename} image to JPEG from HEIC. ${JSON.stringify(error)}`);
|
||||
// }
|
||||
// }
|
||||
// async function handleOriginalFile(file: Express.Multer.File, convertedFileName: string) {
|
||||
// if (process.env.KEEP_CONVERTED_ORIGINALS) {
|
||||
// await fs.ensureDir(path.join(file.destination, FolderPaths.ConvertedOriginalSubDir));
|
||||
// await fs.move(file.path, `${path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)}/${file.filename}`);
|
||||
// } else {
|
||||
// await fs.unlink(file.path);
|
||||
// }
|
||||
// }
|
||||
|
||||
async function ConvertToJpeg(file: string, newPath: string) {
|
||||
const fileOnDisk: Buffer = await fs.readFile(file);
|
||||
// async function ConvertToJpeg(file: string, newPath: string) {
|
||||
// const fileOnDisk: Buffer = await fs.readFile(file);
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
imageMagick(fileOnDisk)
|
||||
.setFormat("jpg")
|
||||
.write(newPath, (error) => {
|
||||
if (error) reject(error.message);
|
||||
resolve(newPath);
|
||||
});
|
||||
});
|
||||
}
|
||||
// return new Promise<string>((resolve, reject) => {
|
||||
// imageMagick(fileOnDisk)
|
||||
// .setFormat("jpg")
|
||||
// .write(newPath, (error) => {
|
||||
// if (error) reject(error.message);
|
||||
// resolve(newPath);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user