add job object, and tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import events from 'events';
|
||||
import createClient from './helpers/create_client';
|
||||
import Job from './job.js';
|
||||
import { omit } from 'lodash';
|
||||
|
||||
export default class Elastique extends events.EventEmitter {
|
||||
@@ -9,6 +10,7 @@ export default class Elastique extends events.EventEmitter {
|
||||
super();
|
||||
|
||||
this.ready = true;
|
||||
this.jobs = [];
|
||||
this.index = index;
|
||||
this.settings = Object.assign({
|
||||
interval: '1w',
|
||||
@@ -22,6 +24,8 @@ export default class Elastique extends events.EventEmitter {
|
||||
timeout: this.settings.timeout
|
||||
}, opts);
|
||||
|
||||
var job = new Job(this, type, payload, options);
|
||||
this.jobs.push(job.id);
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
src/job.js
Normal file
19
src/job.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import events from 'events';
|
||||
import { isPlainObject } from 'lodash';
|
||||
|
||||
export default class Job extends events.EventEmitter {
|
||||
constructor(queue, type, payload, options = {}) {
|
||||
if (typeof type !== 'string') throw new Error('Type must be a string');
|
||||
if (!isPlainObject(payload)) throw new Error('Payload must be a plain object');
|
||||
|
||||
super();
|
||||
|
||||
queue.client.index({
|
||||
index: queue.index,
|
||||
type: type,
|
||||
body: Object.assign({}, options, {
|
||||
payload: payload
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user