add optional created_by record to the doc
This commit is contained in:
@@ -20,6 +20,7 @@ export default class Job extends events.EventEmitter {
|
|||||||
this.index = index;
|
this.index = index;
|
||||||
this.jobtype = type;
|
this.jobtype = type;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
|
this.created_by = options.created_by || null;
|
||||||
this.timeout = options.timeout || 10000;
|
this.timeout = options.timeout || 10000;
|
||||||
this.maxAttempts = options.max_attempts || 3;
|
this.maxAttempts = options.max_attempts || 3;
|
||||||
this.priority = Math.max(Math.min(options.priority || 10, 20), -20);
|
this.priority = Math.max(Math.min(options.priority || 10, 20), -20);
|
||||||
@@ -37,6 +38,7 @@ export default class Job extends events.EventEmitter {
|
|||||||
jobtype: this.jobtype,
|
jobtype: this.jobtype,
|
||||||
payload: this.payload,
|
payload: this.payload,
|
||||||
priority: this.priority,
|
priority: this.priority,
|
||||||
|
created_by: this.created_by,
|
||||||
timeout: this.timeout,
|
timeout: this.timeout,
|
||||||
process_expiration: new Date(0), // use epoch so the job query works
|
process_expiration: new Date(0), // use epoch so the job query works
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
@@ -87,6 +89,7 @@ export default class Job extends events.EventEmitter {
|
|||||||
index: this.index,
|
index: this.index,
|
||||||
type: this.doctype,
|
type: this.doctype,
|
||||||
jobtype: this.jobtype,
|
jobtype: this.jobtype,
|
||||||
|
created_by: this.created_by,
|
||||||
payload: this.payload,
|
payload: this.payload,
|
||||||
timeout: this.timeout,
|
timeout: this.timeout,
|
||||||
max_attempts: this.maxAttempts,
|
max_attempts: this.maxAttempts,
|
||||||
|
|||||||
1
test/fixtures/elasticsearch.js
vendored
1
test/fixtures/elasticsearch.js
vendored
@@ -32,6 +32,7 @@ Client.prototype.get = function (params = {}, source = {}) {
|
|||||||
|
|
||||||
const _source = Object.assign({
|
const _source = Object.assign({
|
||||||
jobtype: 'jobtype',
|
jobtype: 'jobtype',
|
||||||
|
created_by: null,
|
||||||
payload: {
|
payload: {
|
||||||
id: 'sample-job-1',
|
id: 'sample-job-1',
|
||||||
now: 'Mon Apr 25 2016 14:13:04 GMT-0700 (MST)'
|
now: 'Mon Apr 25 2016 14:13:04 GMT-0700 (MST)'
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const Job = module;
|
|||||||
const maxPriority = 20;
|
const maxPriority = 20;
|
||||||
const minPriority = -20;
|
const minPriority = -20;
|
||||||
const defaultPriority = 10;
|
const defaultPriority = 10;
|
||||||
|
const defaultCreatedBy = null;
|
||||||
|
|
||||||
describe('Job Class', function () {
|
describe('Job Class', function () {
|
||||||
let client;
|
let client;
|
||||||
@@ -90,6 +91,24 @@ describe('Job Class', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should index the created_by value', function () {
|
||||||
|
const createdBy = 'user_identifier';
|
||||||
|
const job = new Job(client, index, type, payload, Object.assign({ created_by: createdBy }, options));
|
||||||
|
return job.ready.then(() => {
|
||||||
|
const newDoc = validateDoc(client.index);
|
||||||
|
expect(newDoc.body).to.have.property('created_by', createdBy);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should index default created_by value', function () {
|
||||||
|
const job = new Job(client, index, type, payload, options);
|
||||||
|
return job.ready.then(() => {
|
||||||
|
const newDoc = validateDoc(client.index);
|
||||||
|
expect(newDoc.body).to.have.property('created_by', defaultCreatedBy);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should index timeout value from options', function () {
|
it('should index timeout value from options', function () {
|
||||||
const job = new Job(client, index, type, payload, options);
|
const job = new Job(client, index, type, payload, options);
|
||||||
return job.ready.then(() => {
|
return job.ready.then(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user