Compare commits
4 Commits
e94c6f5d49
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cbde45293 | |||
| 559c7d64d6 | |||
| ed6186f63b | |||
| aefbcabac0 |
15
bin/index.js
15
bin/index.js
@@ -7,12 +7,12 @@ const logger = require('../src/lib/logger.mjs').default;
|
||||
|
||||
const esHost = process.env.ELASTICSEARCH_HOST || 'localhost';
|
||||
const esPort = process.env.ELASTICSEARCH_PORT || '9200';
|
||||
const auth = process.env.ELASTICSEARCH_AUTH || '';
|
||||
|
||||
const { index, interval, lat, lon, radius, ...elasticsearch } = getopts(process.argv.slice(2), {
|
||||
const { index, interval, lat, lon, radius, ...esConfig } = getopts(process.argv.slice(2), {
|
||||
string: ['host', 'auth', 'log', 'index'],
|
||||
alias: {
|
||||
h: 'host',
|
||||
u: 'auth',
|
||||
l: 'log',
|
||||
i: 'index',
|
||||
t: 'interval',
|
||||
@@ -34,14 +34,21 @@ function handleError(err) {
|
||||
}
|
||||
|
||||
async function fetchAndIndex() {
|
||||
logger.debug('Fetching and indexing data...');
|
||||
return mod(index, { elasticsearch, filter: { lat, lon, radius } });
|
||||
return mod(index, { elasticsearch: { ...esConfig, auth }, filter: { lat, lon, radius } });
|
||||
}
|
||||
|
||||
async function run() {
|
||||
// initial kickoff
|
||||
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
|
||||
if (interval === 0) return;
|
||||
logger.debug(`Starting interval (${interval}s)...`);
|
||||
|
||||
@@ -17,7 +17,6 @@ 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,10 +58,8 @@ export async function createIndex(client, index) {
|
||||
})
|
||||
.catch(err => {
|
||||
// check for existing index
|
||||
if (err instanceof BadRequest) {
|
||||
logger.debug(`Index exists: ${realIndex}`);
|
||||
if (err instanceof BadRequest)
|
||||
return client.indices.get({ index: realIndex }).then(() => realIndex);
|
||||
}
|
||||
|
||||
throw err;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user