|
|
|
|
@@ -24,7 +24,7 @@ const ses = new aws.SES({
|
|
|
|
|
|
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
|
|
|
SES: { ses, aws },
|
|
|
|
|
sendingRate: 40 // 40 emails per second.
|
|
|
|
|
sendingRate: InstanceManager({ imex: 40, rome: 10 })
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Initialize the Tasks Email Queue
|
|
|
|
|
@@ -41,38 +41,28 @@ const tasksEmailQueueCleanup = async () => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Handling SIGINT (e.g., Ctrl+C)
|
|
|
|
|
process.on("SIGINT", async () => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
// Handling SIGTERM (e.g., sent by system shutdown)
|
|
|
|
|
process.on("SIGTERM", async () => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
// Handling uncaught exceptions
|
|
|
|
|
process.on("uncaughtException", async (err) => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(1); // Exit with an 'error' code
|
|
|
|
|
});
|
|
|
|
|
// Handling unhandled promise rejections
|
|
|
|
|
process.on("unhandledRejection", async (reason, promise) => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(1); // Exit with an 'error' code
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const fromEmails = InstanceManager({
|
|
|
|
|
imex: "ImEX Online <noreply@imex.online>",
|
|
|
|
|
rome: "Rome Online <noreply@romeonline.io>",
|
|
|
|
|
promanager: "ProManager <noreply@promanager.web-est.com>"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const endPoints = InstanceManager({
|
|
|
|
|
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
|
|
|
|
|
rome: process.env?.NODE_ENV === "test" ? "https//test.romeonline.io" : "https://romeonline.io",
|
|
|
|
|
promanager: process.env?.NODE_ENV === "test" ? "https//test.promanager.web-est.com" : "https://promanager.web-est.com"
|
|
|
|
|
});
|
|
|
|
|
if (process.env.NODE_ENV !== "development") {
|
|
|
|
|
// Handling SIGINT (e.g., Ctrl+C)
|
|
|
|
|
process.on("SIGINT", async () => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
// Handling SIGTERM (e.g., sent by system shutdown)
|
|
|
|
|
process.on("SIGTERM", async () => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(0);
|
|
|
|
|
});
|
|
|
|
|
// Handling uncaught exceptions
|
|
|
|
|
process.on("uncaughtException", async (err) => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(1); // Exit with an 'error' code
|
|
|
|
|
});
|
|
|
|
|
// Handling unhandled promise rejections
|
|
|
|
|
process.on("unhandledRejection", async (reason, promise) => {
|
|
|
|
|
await tasksEmailQueueCleanup();
|
|
|
|
|
process.exit(1); // Exit with an 'error' code
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format the date for the email.
|
|
|
|
|
@@ -105,6 +95,17 @@ const formatPriority = (priority) => {
|
|
|
|
|
* @returns {{header, body: string, subHeader: string}}
|
|
|
|
|
*/
|
|
|
|
|
const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, job, taskId) => {
|
|
|
|
|
const endPoints = InstanceManager({
|
|
|
|
|
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
|
|
|
|
|
rome:
|
|
|
|
|
bodyshop.convenient_company === "promanager"
|
|
|
|
|
? process.env?.NODE_ENV === "test"
|
|
|
|
|
? "https//test.promanager.web-est.com"
|
|
|
|
|
: "https://promanager.web-est.com"
|
|
|
|
|
: process.env?.NODE_ENV === "test"
|
|
|
|
|
? "https//test.romeonline.io"
|
|
|
|
|
: "https://romeonline.io"
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
header: title,
|
|
|
|
|
subHeader: `Body Shop: ${bodyshop.shopname} | Priority: ${formatPriority(priority)} ${formatDate(dueDate)}`,
|
|
|
|
|
@@ -121,12 +122,15 @@ const generateTemplateArgs = (title, priority, description, dueDate, bodyshop, j
|
|
|
|
|
* @param taskIds
|
|
|
|
|
* @param successCallback
|
|
|
|
|
*/
|
|
|
|
|
const sendMail = (type, to, subject, html, taskIds, successCallback) => {
|
|
|
|
|
// Push next messages to Nodemailer
|
|
|
|
|
//transporter.once("idle", () => {
|
|
|
|
|
// Note: This is commented out because despite being in the documentation, it does not work
|
|
|
|
|
// and stackoverflow suggests it is not needed
|
|
|
|
|
// if (transporter.isIdle()) {
|
|
|
|
|
const sendMail = (type, to, subject, html, taskIds, successCallback, requestInstance) => {
|
|
|
|
|
const fromEmails = InstanceManager({
|
|
|
|
|
imex: "ImEX Online <noreply@imex.online>",
|
|
|
|
|
rome:
|
|
|
|
|
requestInstance === "promanager"
|
|
|
|
|
? "ProManager <noreply@promanager.web-est.com>"
|
|
|
|
|
: "Rome Online <noreply@romeonline.io>"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
transporter.sendMail(
|
|
|
|
|
{
|
|
|
|
|
from: fromEmails,
|
|
|
|
|
@@ -184,7 +188,8 @@ const taskAssignedEmail = async (req, res) => {
|
|
|
|
|
tasks_by_pk.job,
|
|
|
|
|
newTask.id
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
tasks_by_pk.bodyshop.convenient_company
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// We return success regardless because we don't want to block the event trigger.
|
|
|
|
|
@@ -233,6 +238,14 @@ const tasksRemindEmail = async (req, res) => {
|
|
|
|
|
|
|
|
|
|
// Iterate over all recipients and send the email.
|
|
|
|
|
recipientCounts.forEach((recipient) => {
|
|
|
|
|
const fromEmails = InstanceManager({
|
|
|
|
|
imex: "ImEX Online <noreply@imex.online>",
|
|
|
|
|
rome:
|
|
|
|
|
onlyTask.bodyshop.convenient_company === "promanager"
|
|
|
|
|
? "ProManager <noreply@promanager.web-est.com>"
|
|
|
|
|
: "Rome Online <noreply@romeonline.io>"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emailData = {
|
|
|
|
|
from: fromEmails,
|
|
|
|
|
to: recipient.email
|
|
|
|
|
@@ -261,6 +274,18 @@ const tasksRemindEmail = async (req, res) => {
|
|
|
|
|
}
|
|
|
|
|
// There are multiple emails to send to this author.
|
|
|
|
|
else {
|
|
|
|
|
const endPoints = InstanceManager({
|
|
|
|
|
imex: process.env?.NODE_ENV === "test" ? "https://test.imex.online" : "https://imex.online",
|
|
|
|
|
rome:
|
|
|
|
|
allTasks[0].bodyshop.convenient_company === "promanager"
|
|
|
|
|
? process.env?.NODE_ENV === "test"
|
|
|
|
|
? "https//test.promanager.web-est.com"
|
|
|
|
|
: "https://promanager.web-est.com"
|
|
|
|
|
: process.env?.NODE_ENV === "test"
|
|
|
|
|
? "https//test.romeonline.io"
|
|
|
|
|
: "https://romeonline.io"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const allTasks = groupedTasks[recipient.email];
|
|
|
|
|
emailData.subject = `New Tasks Reminder - ${allTasks.length} Tasks require your attention`;
|
|
|
|
|
emailData.html = generateEmailTemplate({
|
|
|
|
|
|