chore: replace node-cron with interval-promise

This commit is contained in:
2018-11-02 15:24:33 -07:00
parent d290165899
commit 7eeb251c6b
3 changed files with 11 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
/* eslint no-global-assign: 0 no-console: 0 */
require = require('esm')(module);
const getopts = require('getopts');
const cron = require('node-cron');
const runInterval = require('interval-promise');
const mod = require('../src/index.mjs').default;
const logger = require('../src/lib/logger.mjs').default;
@@ -31,6 +31,7 @@ function handleError(err) {
}
async function fetchAndIndex() {
logger.debug('Fetching and indexing data...');
return mod(index, { elasticsearch, filter: { lat, lon, radius } });
}
@@ -38,14 +39,10 @@ async function run() {
// initial kickoff
await fetchAndIndex().catch(handleError);
if (interval === 0) return;
// scheduled running
logger.debug(`Starting cron (${interval}s)...`);
cron.schedule(`${interval} * * * * *`, () => {
logger.debug('Running cron...');
fetchAndIndex();
});
if (interval === 0) return;
logger.debug(`Starting interval (${interval}s)...`);
runInterval(fetchAndIndex, interval * 1000);
}
run().catch(handleError);