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