Changed logic for checkup.For testing.
This commit is contained in:
@@ -14,6 +14,8 @@ const DEFAULT_TIMEZONE = "Europe/Sarajevo";
|
|||||||
const CRAWLER_INTERVAL = parseInt(process.env.CRAWLER_INTERVAL) || 60;
|
const CRAWLER_INTERVAL = parseInt(process.env.CRAWLER_INTERVAL) || 60;
|
||||||
const STOP_CRAWLER = !!parseInt(process.env.STOP_CRAWLER);
|
const STOP_CRAWLER = !!parseInt(process.env.STOP_CRAWLER);
|
||||||
|
|
||||||
|
const CHECK_UP_DAYS = parseInt(process.env.CHECK_UP_DAYS) || 10;
|
||||||
|
|
||||||
const AWS_EMAIL_CONFIG = {
|
const AWS_EMAIL_CONFIG = {
|
||||||
REGION: process.env.AWS_REGION || "",
|
REGION: process.env.AWS_REGION || "",
|
||||||
CREDENTIALS: {
|
CREDENTIALS: {
|
||||||
@@ -42,5 +44,6 @@ module.exports = {
|
|||||||
MAX_REAL_ESTATES_IN_EMAIL,
|
MAX_REAL_ESTATES_IN_EMAIL,
|
||||||
MAX_REAL_ESTATES_IN_FIRST_EMAIL,
|
MAX_REAL_ESTATES_IN_FIRST_EMAIL,
|
||||||
PRINT_CRAWLER_DEBUG,
|
PRINT_CRAWLER_DEBUG,
|
||||||
API_MAP_KEY
|
API_MAP_KEY,
|
||||||
|
CHECK_UP_DAYS
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const db = require("../../models/index");
|
const db = require("../../models/index");
|
||||||
|
const { CHECK_UP_DAYS } = require("../../config/appConfig");
|
||||||
|
|
||||||
const findRealEstatesForSearchRequest = async searchRequestId => {
|
const findRealEstatesForSearchRequest = async searchRequestId => {
|
||||||
const query = {
|
const query = {
|
||||||
@@ -41,8 +42,27 @@ const findNotNotifiedMatches = async () => {
|
|||||||
return matchingRecords;
|
return matchingRecords;
|
||||||
};
|
};
|
||||||
const findAllRequestsForCheckUp = async () => {
|
const findAllRequestsForCheckUp = async () => {
|
||||||
|
//First we find IDs of search request that don't need to be emailed for check up - to EXCLUDE
|
||||||
|
//The ones that received notification for real estate CHECK_UP_DAYS days from now
|
||||||
|
const date = new Date();
|
||||||
|
const checkUpDate = date.getDate() - CHECK_UP_DAYS;
|
||||||
|
date.setDate(checkUpDate);
|
||||||
|
const dateQuery = {
|
||||||
|
createdAt: {
|
||||||
|
[Op.gte]: date
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const excludedRequests = await db.SearchRequestMatch.findAll({
|
||||||
|
attributes: ["searchRequestId"],
|
||||||
|
where: dateQuery
|
||||||
|
});
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
subscribed: true
|
subscribed: true,
|
||||||
|
id: {
|
||||||
|
[Op.notIn]: excludedRequests
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const allRequestsForCheckUp = await db.SearchRequest.findAll({
|
const allRequestsForCheckUp = await db.SearchRequest.findAll({
|
||||||
where: query
|
where: query
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const { checkUpNotifyAll } = require("../services/notificationService");
|
const { checkUpNotify } = require("../services/notificationService");
|
||||||
|
//For testing pursposes
|
||||||
(async () => {
|
(async () => {
|
||||||
await checkUpNotifyAll();
|
await checkUpNotify();
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ const notifyRequestsWithDailyOption = async () => {
|
|||||||
await notifyMatches(matches, true);
|
await notifyMatches(matches, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkUpNotifyAll = async () => {
|
const checkUpNotify = async () => {
|
||||||
const searchRequestsForCheckUp = await findAllRequestsForCheckUp();
|
const searchRequestsForCheckUp = await findAllRequestsForCheckUp();
|
||||||
|
|
||||||
const asyncSendEmailActions = [];
|
const asyncSendEmailActions = [];
|
||||||
@@ -134,5 +134,5 @@ module.exports = {
|
|||||||
notifyForNewRealEstates,
|
notifyForNewRealEstates,
|
||||||
notifyForNewSearchRequest,
|
notifyForNewSearchRequest,
|
||||||
notifyRequestsWithDailyOption,
|
notifyRequestsWithDailyOption,
|
||||||
checkUpNotifyAll
|
checkUpNotify
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ APP_BASE_URL=base url for the app
|
|||||||
MAX_REAL_ESTATES_IN_EMAIL=Max number of real estates that will be shown in email, others will be truncated and URL with full list will be shwon
|
MAX_REAL_ESTATES_IN_EMAIL=Max number of real estates that will be shown in email, others will be truncated and URL with full list will be shwon
|
||||||
MAX_REAL_ESTATES_IN_FIRST_EMAIL=Max number of real estates that will be shown in first (welcome) email
|
MAX_REAL_ESTATES_IN_FIRST_EMAIL=Max number of real estates that will be shown in first (welcome) email
|
||||||
|
|
||||||
|
CHECK_UP_DAYS=Check up email is sent after this number of days without notification
|
||||||
#=============== GOOGLE ANALYTICS =============#
|
#=============== GOOGLE ANALYTICS =============#
|
||||||
GA_ID=Google Analytics ID
|
GA_ID=Google Analytics ID
|
||||||
|
|
||||||
|
|||||||
7
index.js
7
index.js
@@ -8,10 +8,12 @@ const forceSSL = require("./app/helpers/forceSSL");
|
|||||||
const {
|
const {
|
||||||
APP_PORT,
|
APP_PORT,
|
||||||
CRAWLER_INTERVAL,
|
CRAWLER_INTERVAL,
|
||||||
STOP_CRAWLER
|
STOP_CRAWLER,
|
||||||
|
CHECK_UP_DAYS
|
||||||
} = require("./app/config/appConfig");
|
} = require("./app/config/appConfig");
|
||||||
const routes = require("./app/routes");
|
const routes = require("./app/routes");
|
||||||
const { crawlAll } = require("./app/crawler/crawl");
|
const { crawlAll } = require("./app/crawler/crawl");
|
||||||
|
const { checkUpNotify } = require("./app/services/notificationService");
|
||||||
const {
|
const {
|
||||||
notifyForNewRealEstates
|
notifyForNewRealEstates
|
||||||
} = require("./app/services/notificationService");
|
} = require("./app/services/notificationService");
|
||||||
@@ -45,4 +47,7 @@ const crawl = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
setInterval(crawl, CRAWLER_INTERVAL * 1000);
|
setInterval(crawl, CRAWLER_INTERVAL * 1000);
|
||||||
|
|
||||||
|
setInterval(checkUpNotify, CHECK_UP_DAYS * 24 * 60 * 60 * 1000);
|
||||||
|
|||||||
Reference in New Issue
Block a user