diff --git a/changedetection.js b/changedetection.js index 48c789b..b2e298f 100644 --- a/changedetection.js +++ b/changedetection.js @@ -8,6 +8,9 @@ const ChangeDetection = require('./scrapers/scraper'); async function run() { const cdScraper = new ChangeDetection(); + let startTime = new Date(); + let startTimeStamp = startTime.getTime(); + const delay = process.env.DELAY || 600000; if (typeof(process.env.CD_CRON) === 'string' ) { console.log(`${cdScraper.id} cron set for ${process.env.CD_CRON}`); @@ -26,11 +29,18 @@ async function run() { await cdScraper.run(); console.log('--'); setInterval(async () => { - console.log('go'); - await cdScraper.run(); - console.log('ready to go again..'); - // }, parseInt(process.env.CD_EVERY, 10)); - }, process.env.CD_EVERY); + const now = new Date(); + const nowTS = now.getTime(); + + console.log('check'); + + if (nowTS - startTimeStamp > process.env.CD_EVERY) { + await cdScraper.run(); + console.log('ready to go again..'); + startTime = new Date(); + startTimeStamp = startTime.getTime(); + } + }, delay); } if (process.env.SCRAPE_START === cdScraper.id) {