chore: replace node-cron with interval-promise
This commit is contained in:
13
bin/index.js
13
bin/index.js
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user