Compare commits
1 Commits
master
...
3c020d25ed
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c020d25ed |
@@ -34,6 +34,7 @@ function handleError(err) {
|
||||
}
|
||||
|
||||
async function fetchAndIndex() {
|
||||
logger.debug('Fetching and indexing data...');
|
||||
return mod(index, { elasticsearch: { ...esConfig, auth }, filter: { lat, lon, radius } });
|
||||
}
|
||||
|
||||
@@ -42,12 +43,12 @@ async function run() {
|
||||
await fetchAndIndex().catch(handleError);
|
||||
|
||||
// listen for termination
|
||||
const terminate = type => () => {
|
||||
console.log(`Terminating [${type}]`);
|
||||
const terminate = () => {
|
||||
console.log('Terminating...');
|
||||
process.exit(0);
|
||||
};
|
||||
process.on('SIGINT', terminate('SIGINT'));
|
||||
process.on('SIGTERM', terminate('SIGTERM'));
|
||||
process.on('SIGINT', terminate);
|
||||
process.on('SIGTERM', terminate);
|
||||
|
||||
// scheduled running
|
||||
if (interval === 0) return;
|
||||
|
||||
@@ -17,6 +17,7 @@ export default async function(indexName, opts = {}) {
|
||||
const index = await createIndex(client, indexName);
|
||||
|
||||
const records = await getAdbsExchangeData(opts.filter);
|
||||
logger.debug(`Record count:, ${records.length}`);
|
||||
|
||||
await bulkInsert(client, index, records);
|
||||
logger.debug(`Successfully indexed ${records.length} records to ${index}`);
|
||||
|
||||
@@ -58,8 +58,10 @@ export async function createIndex(client, index) {
|
||||
})
|
||||
.catch(err => {
|
||||
// check for existing index
|
||||
if (err instanceof BadRequest)
|
||||
if (err instanceof BadRequest) {
|
||||
logger.debug(`Index exists: ${realIndex}`);
|
||||
return client.indices.get({ index: realIndex }).then(() => realIndex);
|
||||
}
|
||||
|
||||
throw err;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user