Send templated bulk email, and remember notifed marketalerts
This commit is contained in:
@@ -19,7 +19,7 @@ async function crawlAll() {
|
||||
|
||||
try {
|
||||
|
||||
const marketAlertsFromDb = await allMarketAlerts();
|
||||
const marketAlertsFromDb = await allMarketAlerts(true);
|
||||
console.log("CRAWLER SERVICE: number of existing MarketAlerts from db: " + marketAlertsFromDb.length);
|
||||
|
||||
const marketAlerts = [];
|
||||
@@ -37,7 +37,9 @@ async function crawlAll() {
|
||||
municipality: result.municipality,
|
||||
region: result.region,
|
||||
gardenSize: isNaN(result.gardenSize) ? 0 : result.gardenSize,
|
||||
realEstateType: result.realEstateType
|
||||
realEstateType: result.realEstateType,
|
||||
title: result.title,
|
||||
notified: false
|
||||
})
|
||||
}
|
||||
console.log("CRAWLER SERVICE: Number of crawler results: " + marketAlerts.length);
|
||||
|
||||
@@ -8,11 +8,20 @@ const { createMarketAlertEmailTemplate, sendBulkEmail } = require('../helpers/aw
|
||||
async function processNotifications() {
|
||||
|
||||
try {
|
||||
const marketAlerts = await allMarketAlerts(false);
|
||||
// await createMarketAlertEmailTemplate();
|
||||
await sendBulkEmail(marketAlerts);
|
||||
// console.log(marketAlerts);
|
||||
const marketAlerts = await allMarketAlerts(false, false);
|
||||
console.log(marketAlerts.length)
|
||||
await createMarketAlertEmailTemplate();
|
||||
if (marketAlerts.length > 0) {
|
||||
console.log("NOTIFICATION SERVICE: Number of new alerts: " + marketAlerts.length)
|
||||
await sendBulkEmail(marketAlerts);
|
||||
} else {
|
||||
console.log("NOTIFICATION SERVICE: No new alerts");
|
||||
}
|
||||
|
||||
await db.MarketAlert.update(
|
||||
{ notified: true }, /* set attributes' value */
|
||||
{ where: { notified: false } } /* where criteria */
|
||||
);
|
||||
process.exit();
|
||||
} catch (e) {
|
||||
console.log("NOTIFICATION SERVICE: could not send notifications reason: ", e);
|
||||
|
||||
Reference in New Issue
Block a user