start crawler loop when server is started

This commit is contained in:
Bilal Catic
2019-09-26 17:30:06 +02:00
parent 0b083a02e2
commit 2e92f961ff
6 changed files with 30 additions and 9 deletions

View File

@@ -8,8 +8,11 @@ const APP_URL =
const DEFAULT_TIMEZONE = "Europe/Sarajevo";
const CRAWLER_INTERVAL = parseInt(process.env.CRAWLER_INTERVAL) || 60;
module.exports = {
APP_PORT,
APP_URL,
DEFAULT_TIMEZONE
DEFAULT_TIMEZONE,
CRAWLER_INTERVAL
};

View File

@@ -26,15 +26,14 @@ const crawlers = [
async function crawlAll() {
for (let crawler of crawlers) {
try {
const newRealEstates = await crawler.crawl();
console.log("Number of new real estates : ", newRealEstates.length);
return await crawler.crawl();
} catch (e) {
console.log("Error crawling. Trying next crawler! ", e);
return [];
}
}
}
(async () => {
await crawlAll();
})();
module.exports = {
crawlAll
};

5
app/crawler/npmCrawl.js Normal file
View File

@@ -0,0 +1,5 @@
const { crawlAll } = require("./crawl");
(async () => {
await crawlAll();
})();