add index creation to init tasks
This commit is contained in:
17
src/index.js
17
src/index.js
@@ -1,5 +1,7 @@
|
|||||||
import events from 'events';
|
import events from 'events';
|
||||||
import createClient from './helpers/create_client';
|
import createClient from './helpers/es_client';
|
||||||
|
import indexTimestamp from './helpers/index_timestamp';
|
||||||
|
import createIndex from './helpers/create_index';
|
||||||
import Job from './job.js';
|
import Job from './job.js';
|
||||||
import Worker from './worker.js';
|
import Worker from './worker.js';
|
||||||
import { omit } from 'lodash';
|
import { omit } from 'lodash';
|
||||||
@@ -11,10 +13,21 @@ export default class Elastique extends events.EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.settings = Object.assign({
|
this.settings = Object.assign({
|
||||||
interval: '1w',
|
interval: 'week',
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
}, omit(options, [ 'client' ]));
|
}, omit(options, [ 'client' ]));
|
||||||
this.client = createClient(options.client || {});
|
this.client = createClient(options.client || {});
|
||||||
|
|
||||||
|
this._initTasks().catch((err) => this.emit('error', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
_initTasks() {
|
||||||
|
const timestamp = indexTimestamp(this.settings.interval);
|
||||||
|
var initTasks = [
|
||||||
|
this.client.ping({ timeout: 3000 }),
|
||||||
|
createIndex(this.client, `${this.index}-${timestamp}`),
|
||||||
|
];
|
||||||
|
return Promise.all(initTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
add(type, payload, opts = {}) {
|
add(type, payload, opts = {}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user