create index on job creation
This commit is contained in:
47
src/job.js
47
src/job.js
@@ -1,6 +1,7 @@
|
|||||||
import events from 'events';
|
import events from 'events';
|
||||||
import { isPlainObject, omit } from 'lodash';
|
import { isPlainObject } from 'lodash';
|
||||||
import { JOB_STATUS_PENDING } from './helpers/constants';
|
import { JOB_STATUS_PENDING } from './helpers/constants';
|
||||||
|
import createIndex from './helpers/create_index';
|
||||||
|
|
||||||
export default class Job extends events.EventEmitter {
|
export default class Job extends events.EventEmitter {
|
||||||
constructor(client, index, type, payload, timeout = 10000) {
|
constructor(client, index, type, payload, timeout = 10000) {
|
||||||
@@ -16,25 +17,33 @@ export default class Job extends events.EventEmitter {
|
|||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
this.status = JOB_STATUS_PENDING;
|
this.status = JOB_STATUS_PENDING;
|
||||||
|
|
||||||
this.ready = this.client.index({
|
this.ready = createIndex(client, index)
|
||||||
index: this.index,
|
.then((...args) => {
|
||||||
type: this.type,
|
this.client.index({
|
||||||
body: {
|
index: this.index,
|
||||||
payload: this.payload,
|
type: this.type,
|
||||||
timeout: this.timeout,
|
body: {
|
||||||
created: new Date(),
|
payload: this.payload,
|
||||||
started: null,
|
timeout: this.timeout,
|
||||||
completed: null,
|
created: new Date(),
|
||||||
attempts: 0,
|
started: null,
|
||||||
status: this.status,
|
completed: null,
|
||||||
}
|
attempts: 0,
|
||||||
|
status: this.status,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((doc) => {
|
||||||
|
this.document = {
|
||||||
|
id: doc._id,
|
||||||
|
type: doc._type,
|
||||||
|
version: doc._version,
|
||||||
|
};
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((doc) => {
|
.catch((err) => {
|
||||||
this.document = {
|
this.emit('error', err);
|
||||||
id: doc._id,
|
throw err;
|
||||||
type: doc._type,
|
|
||||||
version: doc._version,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user