From 1b7cb7c852443a77d7ce616c6fdaef08bd96b3e9 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 20 Feb 2025 13:43:22 -0500 Subject: [PATCH] feature/IO-3096-GlobalNotifications - Checkpoint, fixed some email bugs in other files, consolidated the GetEndpoints on the backend, moved the consolidation delays for queues to ENV vars --- server/notifications/queues/appQueue.js | 2 +- server/notifications/queues/emailQueue.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/notifications/queues/appQueue.js b/server/notifications/queues/appQueue.js index 837eb52fc..e7c7ef759 100644 --- a/server/notifications/queues/appQueue.js +++ b/server/notifications/queues/appQueue.js @@ -7,7 +7,7 @@ const APP_CONSOLIDATION_DELAY_IN_MINS = (() => { return isNaN(parsedValue) ? 1 : Math.max(1, parsedValue); // Default to 1, ensure at least 1 })(); -// Base time-related constant (in milliseconds) +// Base time-related constant (in milliseconds) / DO NOT TOUCH const APP_CONSOLIDATION_DELAY = APP_CONSOLIDATION_DELAY_IN_MINS * 60000; // 1 minute (base timeout) // Derived time-related constants based on APP_CONSOLIDATION_DELAY / DO NOT TOUCH, these are pegged to APP_CONSOLIDATION_DELAY diff --git a/server/notifications/queues/emailQueue.js b/server/notifications/queues/emailQueue.js index 302c3665a..ef34196cb 100644 --- a/server/notifications/queues/emailQueue.js +++ b/server/notifications/queues/emailQueue.js @@ -9,7 +9,7 @@ const EMAIL_CONSOLIDATION_DELAY_IN_MINS = (() => { return isNaN(parsedValue) ? 1 : Math.max(1, parsedValue); // Default to 1, ensure at least 1 })(); -// Base time-related constant (in milliseconds) +// Base time-related constant (in milliseconds) / DO NOT TOUCH const EMAIL_CONSOLIDATION_DELAY = EMAIL_CONSOLIDATION_DELAY_IN_MINS * 60000; // 1 minute (base timeout) // Derived time-related constants based on EMAIL_CONSOLIDATION_DELAY / DO NOT TOUCH, these are pegged to EMAIL_CONSOLIDATION_DELAY @@ -58,13 +58,13 @@ const loadEmailQueue = async ({ pubClient, logger }) => { const redisKeyPrefix = `email:notifications:${jobId}`; for (const recipient of recipients) { - const { user } = recipient; + const { user, firstName, lastName } = recipient; const userKey = `${redisKeyPrefix}:${user}`; await pubClient.rpush(userKey, body); await pubClient.expire(userKey, NOTIFICATION_EXPIRATION / 1000); // Set expiration const detailsKey = `email:recipientDetails:${jobId}:${user}`; - await pubClient.hsetnx(detailsKey, "firstName", recipient.firstName || ""); - await pubClient.hsetnx(detailsKey, "lastName", recipient.lastName || ""); + await pubClient.hsetnx(detailsKey, "firstName", firstName || ""); + await pubClient.hsetnx(detailsKey, "lastName", lastName || ""); await pubClient.expire(detailsKey, NOTIFICATION_EXPIRATION / 1000); // Set expiration await pubClient.sadd(`email:recipients:${jobId}`, user); logger.logger.debug(`Stored message for ${user} under ${userKey}: ${body}`); @@ -116,10 +116,11 @@ const loadEmailQueue = async ({ pubClient, logger }) => { if (messages.length > 0) { const details = await pubClient.hgetall(detailsKey); const firstName = details.firstName || "User"; - const subject = `Updates for job ${jobRoNumber} at ${bodyShopName}`; + const multipleUpdateString = messages.length > 1 ? "Updates" : "Update"; + const subject = `${multipleUpdateString} for job ${jobRoNumber} at ${bodyShopName}`; // Use the template instead of inline HTML const emailBody = generateEmailTemplate({ - header: `Updates for Job ${jobRoNumber}`, + header: `${multipleUpdateString} for Job ${jobRoNumber}`, subHeader: `Dear ${firstName},`, body: `

There have been updates to job ${jobRoNumber} at ${bodyShopName}: