Added send notification service, and queried unsent marketalerts, fixed some issues with crawler, and added proper logging
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
const Promise = require("bluebird");
|
||||
const OlxCrawler = require("../helpers/crawlers/olxClawler");
|
||||
const db = require("../models/index");
|
||||
const { allMarketAlerts } = require('../helpers/db/dbHelper');
|
||||
|
||||
const olxCrawler = new OlxCrawler(1, 2, 3);
|
||||
|
||||
@@ -10,6 +11,7 @@ const crawlers = [
|
||||
];
|
||||
|
||||
async function crawlAll() {
|
||||
console.log("CRAWLER SERVICE: crawlAll");
|
||||
|
||||
Promise.map(crawlers, function (crawler) {
|
||||
return crawler.crawl();
|
||||
@@ -17,7 +19,8 @@ async function crawlAll() {
|
||||
|
||||
try {
|
||||
|
||||
const marketAlertsFromDb = await db.MarketAlert.findAll();
|
||||
const marketAlertsFromDb = await allMarketAlerts();
|
||||
console.log("CRAWLER SERVICE: number of existing MarketAlerts from db: " + marketAlertsFromDb.length);
|
||||
|
||||
const marketAlerts = [];
|
||||
const mergedResults = [].concat.apply([], results);
|
||||
@@ -37,16 +40,23 @@ async function crawlAll() {
|
||||
realEstateType: result.realEstateType
|
||||
})
|
||||
}
|
||||
console.log("CRAWLER SERVICE: Number of crawler results: " + marketAlerts.length);
|
||||
|
||||
try {
|
||||
console.log(marketAlerts);
|
||||
const filteredMarketAlerts = marketAlerts.filter((elem) => !marketAlertsFromDb.find(({ url }) => elem.url === url));
|
||||
|
||||
const filteredMarketAlerts = marketAlerts.filter((elem) => !marketAlertsFromDb.find(({ url }) => elem.url === url));
|
||||
console.log("CRAWLER SERVICE: Number of new crawler results: " + filteredMarketAlerts.length);
|
||||
|
||||
await db.MarketAlert.bulkCreate(filteredMarketAlerts);
|
||||
process.exit()
|
||||
process.exit();
|
||||
|
||||
} catch (e) {
|
||||
console.log("Could not bulkCreate marketalers reason: ", e);
|
||||
console.log("CRAWLER SERVICE: Could not bulkCreate marketalers reason: ", e);
|
||||
process.exit();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error crawling. Trying next crawler! ", e);
|
||||
console.log("CRAWLER SERVICE: Error crawling. Trying next crawler! ", e);
|
||||
process.exit();
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user