start crawler loop when server is started
This commit is contained in:
14
index.js
14
index.js
@@ -6,8 +6,9 @@ const bodyParser = require("body-parser");
|
||||
const layout = require("express-layout");
|
||||
const compression = require("compression");
|
||||
|
||||
const { APP_PORT } = require("./app/config/appConfig");
|
||||
const { APP_PORT, CRAWLER_INTERVAL } = require("./app/config/appConfig");
|
||||
const routes = require("./app/routes");
|
||||
const { crawlAll } = require("./app/crawler/crawl");
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -26,3 +27,14 @@ app.use("/assets", express.static("./app/public"));
|
||||
app.listen(APP_PORT, () =>
|
||||
console.log(`Example app listening on port ${APP_PORT}!`)
|
||||
);
|
||||
|
||||
let crawlerRunning = false;
|
||||
const crawl = () => {
|
||||
if (!crawlerRunning) {
|
||||
crawlerRunning = true;
|
||||
crawlAll().then(newRealEstates => {
|
||||
crawlerRunning = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
setInterval(crawl, CRAWLER_INTERVAL * 1000);
|
||||
|
||||
Reference in New Issue
Block a user