create index on job creation
This commit is contained in:
13
src/job.js
13
src/job.js
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user