create index on job creation

This commit is contained in:
2016-04-22 17:47:48 -07:00
parent bb97b7960b
commit 1114bb25b8

View File

@@ -1,6 +1,7 @@
import events from 'events';
import { isPlainObject, omit } from 'lodash';
import { isPlainObject } from 'lodash';
import { JOB_STATUS_PENDING } from './helpers/constants';
import createIndex from './helpers/create_index';
export default class Job extends events.EventEmitter {
constructor(client, index, type, payload, timeout = 10000) {
@@ -16,7 +17,9 @@ export default class Job extends events.EventEmitter {
this.timeout = timeout;
this.status = JOB_STATUS_PENDING;
this.ready = this.client.index({
this.ready = createIndex(client, index)
.then((...args) => {
this.client.index({
index: this.index,
type: this.type,
body: {
@@ -36,5 +39,11 @@ export default class Job extends events.EventEmitter {
version: doc._version,
};
});
})
.catch((err) => {
this.emit('error', err);
throw err;
});
}
}