35 lines
763 B
JavaScript
35 lines
763 B
JavaScript
|
#!/usr/bin/env node
|
||
|
const CronJob = require('cron').CronJob;
|
||
|
|
||
|
// load env variables from file
|
||
|
require('dotenv').config();
|
||
|
|
||
|
const ChangeDetection = require('./scrapers/scraper');
|
||
|
|
||
|
async function run() {
|
||
|
const cdScraper = new ChangeDetection();
|
||
|
|
||
|
if (typeof(process.env.CD_CRON) === 'string' ) {
|
||
|
console.log(`${cdScraper.id} cron set for ${process.env.CD_CRON}`);
|
||
|
new CronJob(process.env.CD_CRON, async function() {
|
||
|
console.log('go');
|
||
|
await cdScraper.run();
|
||
|
}, null, true);
|
||
|
}
|
||
|
|
||
|
if (process.env.SCRAPE_START === cdScraper.id)
|
||
|
{
|
||
|
console.log('go');
|
||
|
await cdScraper.run();
|
||
|
}
|
||
|
|
||
|
console.log('Change Detection Launched');
|
||
|
}
|
||
|
|
||
|
process.once('uncaughtException', function caught(err) {
|
||
|
console.error('Uncaught', err);
|
||
|
});
|
||
|
|
||
|
run();
|
||
|
|