|
|
|
|
@@ -12,7 +12,7 @@ import { FolderPaths } from "./serverInit.js";
|
|
|
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
|
|
|
|
const HeicQueue = new Queue("HEIC Queue", { connection: { host: "localhost", port: 6379 , } });
|
|
|
|
|
const HeicQueue = new Queue("HEIC Queue", { connection: { host: "localhost", port: 6379 } });
|
|
|
|
|
|
|
|
|
|
dotenv.config({
|
|
|
|
|
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
|
|
|
|
@@ -23,8 +23,12 @@ const imageMagick = gm.subClass({ imageMagick: true });
|
|
|
|
|
export async function ConvertHeicFiles(files: Express.Multer.File[]) {
|
|
|
|
|
const validFiles = await filterValidHeicFiles(files);
|
|
|
|
|
|
|
|
|
|
const jobs = await HeicQueue.addBulk(validFiles.map(file => ({name: file.filename, data: {convertedFileName:generateUniqueHeicFilename(file) , file} })))
|
|
|
|
|
logger.log("debug", `The Jobs Object ${(JSON.stringify(jobs,null,2))}`)
|
|
|
|
|
const jobs = await HeicQueue.addBulk(
|
|
|
|
|
validFiles.map((file) => ({
|
|
|
|
|
name: file.filename,
|
|
|
|
|
data: { convertedFileName: generateUniqueHeicFilename(file), file }
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
// await Promise.all(
|
|
|
|
|
// validFiles.map(async (file) => {
|
|
|
|
|
// const convertedFileName = generateUniqueHeicFilename(file);
|
|
|
|
|
@@ -96,43 +100,46 @@ const HeicWorker = new Worker(
|
|
|
|
|
file.path = `${file.destination}/${convertedFileName}`;
|
|
|
|
|
return true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.log("error", `QUEUE ERROR: Error converting ${file.filename} image to JPEG from HEIC. ${JSON.stringify(error)}`);
|
|
|
|
|
logger.log(
|
|
|
|
|
"error",
|
|
|
|
|
`QUEUE ERROR: Error converting ${file.filename} image to JPEG from HEIC. ${JSON.stringify(error)}`
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
connection: { host: "localhost", port: 6379 },
|
|
|
|
|
connection: { host: "localhost", port: 6379 }
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
HeicQueue.on('waiting', job => {
|
|
|
|
|
logger.log("debug", `Job is waiting in queue! ${job.data.convertedFileName}`);
|
|
|
|
|
})
|
|
|
|
|
HeicQueue.on('error', error => {
|
|
|
|
|
logger.log("error", `Queue Error! ${error}`);
|
|
|
|
|
})
|
|
|
|
|
HeicQueue.on("waiting", (job) => {
|
|
|
|
|
logger.log("debug", `[BULLMQ] Job is waiting in queue! ${job.data.convertedFileName}`);
|
|
|
|
|
});
|
|
|
|
|
HeicQueue.on("error", (error) => {
|
|
|
|
|
logger.log("error", `[BULLMQ] Queue Error! ${error}`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
HeicWorker.on("ready", () => {
|
|
|
|
|
logger.log('debug',`Worker Ready`);
|
|
|
|
|
logger.log("debug", `[BULLMQ] Worker Ready`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on("active", (job, prev) => {
|
|
|
|
|
logger.log('debug',`Job ${job.id} is now active; previous status was ${prev}`);
|
|
|
|
|
logger.log("debug", `[BULLMQ] Job ${job.id} is now active; previous status was ${prev}`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on("completed", (jobId, returnvalue) => {
|
|
|
|
|
logger.log('debug',`${jobId.id} has completed and returned ${returnvalue}`);
|
|
|
|
|
logger.log("debug", `[BULLMQ] ${jobId.id} has completed and returned ${returnvalue}`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on("failed", (jobId, failedReason) => {
|
|
|
|
|
logger.log('error',`${jobId} has failed with reason ${failedReason}`);
|
|
|
|
|
logger.log("error", `[BULLMQ] ${jobId} has failed with reason ${failedReason}`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on("error", (error) => {
|
|
|
|
|
logger.log("error", `[BULLMQ] There was a queue error! ${error}`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on("stalled", (error) => {
|
|
|
|
|
logger.log("error", `[BULLMQ] There was a worker stall! ${error}`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on("ioredis:close", () => {
|
|
|
|
|
logger.log("error", `[BULLMQ] Redis connection closed!`);
|
|
|
|
|
});
|
|
|
|
|
HeicWorker.on('error', error => {
|
|
|
|
|
logger.log('error', `There was a queue error! ${error}`)
|
|
|
|
|
})
|
|
|
|
|
HeicWorker.on('stalled', error => {
|
|
|
|
|
logger.log('error', `There was a worker stall! ${error}`)
|
|
|
|
|
})
|
|
|
|
|
HeicWorker.on('ioredis:close', () => {
|
|
|
|
|
logger.log('error', `Redis connection closed!`)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// const queueEvents = new QueueEvents( "HEIC Queue");
|
|
|
|
|
|
|
|
|
|
|