feature/IO-3096-GlobalNotifications - Checkpoint, BULLMQ!
This commit is contained in:
40
server/notifications/queues/emailQueue.js
Normal file
40
server/notifications/queues/emailQueue.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { Queue, Worker } = require("bullmq");
|
||||
|
||||
let emailQueue;
|
||||
|
||||
const loadEmailQueue = async ({ pubClient, logger, redisHelpers }) => {
|
||||
if (!emailQueue) {
|
||||
logger.logger.info("Initializing Notifications Email Queue");
|
||||
emailQueue = await new Queue("notificationsEmails", { connection: pubClient, prefix: "{BULLMQ}" });
|
||||
}
|
||||
|
||||
// TODO: Test code for worker
|
||||
// const worker = new Worker(
|
||||
// "notificationsEmails",
|
||||
// async (job) => {
|
||||
// console.log("Processing job", job.id, "with data", job.data);
|
||||
// // Simulate some work
|
||||
// await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait for 2 seconds
|
||||
// console.log("Job processed");
|
||||
// },
|
||||
// { connection: pubClient, prefix: "{BULLMQ}" }
|
||||
// );
|
||||
//
|
||||
// worker.on("completed", (job) => {
|
||||
// console.log(`Job ${job.id} completed!`);
|
||||
// // Optionally, close the worker after it's done
|
||||
// worker.close().then(() => {
|
||||
// console.log("Worker closed");
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// worker.on("error", (err) => {
|
||||
// console.error("Error in worker:", err);
|
||||
// });
|
||||
|
||||
return emailQueue;
|
||||
};
|
||||
|
||||
const getQueue = () => (!emailQueue ? loadEmailQueue : emailQueue);
|
||||
|
||||
module.exports = getQueue;
|
||||
Reference in New Issue
Block a user