From 2d4333991102ec5156a0e69e29c5510740a1bcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20de=20Vasconcelos?= Date: Tue, 7 Nov 2023 22:55:38 +0000 Subject: [PATCH] Update index.js --- notifier/index.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/notifier/index.js b/notifier/index.js index 2ee64a6..c17bba9 100644 --- a/notifier/index.js +++ b/notifier/index.js @@ -37,29 +37,33 @@ const RUN_INTERVAL = 30000; // seconds // Iterate on each ready job to notify its owner for (const jobData of allReadyJobs) { - // + try { + // - // Skip if already notified job owner - if (jobData.notification_count > 0) continue; + // Skip if already notified job owner + if (jobData.notification_count > 0) continue; - // Skip if job has no onwer email - if (!jobData.owner_email) continue; + // Skip if job has no onwer email + if (!jobData.owner_email) continue; - // Send an email to the owner - await SMTPSERVICE.transport.sendMail({ - from: `"Carris Metropolitana" `, - to: `"${jobData.owner_name || ''}" <${jobData.owner_email}>`, - subject: `O seu PDF está pronto!`, - html: `Clique para Download
${JSON.stringify(jobData)}
`, - }); + // Send an email to the owner + await SMTPSERVICE.transport.sendMail({ + from: `"Carris Metropolitana" `, + to: `"${jobData.owner_name || ''}" <${jobData.owner_email}>`, + subject: `O seu PDF está pronto!`, + html: `Clique para Download
${JSON.stringify(jobData)}
`, + }); - // Update status of this job - await QUEUEDB.Job.updateOne({ _id: jobData._id }, { $set: { notification_count: jobData.notification_count++, date_notified: [...jobData.date_notified, new Date().toISOString()] } }); + // Update status of this job + await QUEUEDB.Job.updateOne({ _id: jobData._id }, { $set: { notification_count: jobData.notification_count++, date_notified: [...jobData.date_notified, new Date().toISOString()] } }); - // Log progress - console.log(`→ id: ${jobData._id} | owner_email: ${jobData.owner_email}`); + // Log progress + console.log(`→ id: ${jobData._id} | owner_email: ${jobData.owner_email}`); - // + // + } catch (err) { + console.log('🔴 → Error notifying "%s"', jobData._id, err); + } } // Switch the flag OFF