1 Commits

Author SHA1 Message Date
e94c6f5d49 feat: make it fake data 2019-01-28 14:25:59 -07:00
4 changed files with 9 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
# fake-adsb-index
# adsb-index
FAKE ADS-B indexing script.

View File

@@ -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, ...esConfig } = getopts(process.argv.slice(2), {
const { index, interval, lat, lon, radius, ...elasticsearch } = getopts(process.argv.slice(2), {
string: ['host', 'auth', 'log', 'index'],
alias: {
h: 'host',
u: 'auth',
l: 'log',
i: 'index',
t: 'interval',
@@ -34,21 +34,14 @@ function handleError(err) {
}
async function fetchAndIndex() {
return mod(index, { elasticsearch: { ...esConfig, auth }, filter: { lat, lon, radius } });
logger.debug('Fetching and indexing data...');
return mod(index, { elasticsearch, 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)...`);

View File

@@ -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}`);

View File

@@ -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;
});