diff --git a/src/job.js b/src/job.js index d7f644f..446f1f1 100644 --- a/src/job.js +++ b/src/job.js @@ -3,7 +3,7 @@ import { isPlainObject, omit } from 'lodash'; import { JOB_STATUS_PENDING } from './helpers/constants'; export default class Job extends events.EventEmitter { - constructor(queue, type, payload, options = {}) { + constructor(queue, type, payload, timeout = 10000) { if (typeof type !== 'string') throw new Error('Type must be a string'); if (!isPlainObject(payload)) throw new Error('Payload must be a plain object'); @@ -12,8 +12,7 @@ export default class Job extends events.EventEmitter { this.queue = queue; this.type = type; this.payload = payload; - this.timeout = options.timeout || 10000; - this.options = omit(options, [ 'timeout' ]); + this.timeout = timeout; this.status = JOB_STATUS_PENDING; this.ready = this.queue.client.index({ @@ -22,7 +21,6 @@ export default class Job extends events.EventEmitter { body: { payload: this.payload, timeout: this.timeout, - options: this.options, created: new Date(), started: null, completed: null, diff --git a/test/src/job.js b/test/src/job.js index 8bbca08..c241c1e 100644 --- a/test/src/job.js +++ b/test/src/job.js @@ -39,10 +39,9 @@ describe('Job Class', function () { }); describe('construction', function () { - const PENDING = 0; let type; let payload; - let options; + let timeout; function validateDoc(spy) { expect(spy.callCount).to.be(1); @@ -53,7 +52,7 @@ describe('Job Class', function () { beforeEach(function () { type = 'type1'; payload = { id: '123' }; - options = { timeout: 1234, test: 'options' }; + timeout = 4567; sinon.spy(mockQueue.client, 'index'); }); @@ -66,26 +65,14 @@ describe('Job Class', function () { expect(newDoc.body).to.have.property('payload', payload); }); - it('should index any optional params', function () { - new Job(mockQueue, type, payload, options); - const newDoc = validateDoc(mockQueue.client.index); - expect(newDoc.body).to.have.property('options'); - }); - it('should index timeout value from options', function () { - new Job(mockQueue, type, payload, options); + new Job(mockQueue, type, payload, timeout); const newDoc = validateDoc(mockQueue.client.index); - expect(newDoc.body).to.have.property('timeout', options.timeout); - }); - - it('should not use timeout as an option', function () { - new Job(mockQueue, type, payload, options); - const newDoc = validateDoc(mockQueue.client.index); - expect(newDoc.body.options).to.eql(_.omit(options, [ 'timeout' ])); + expect(newDoc.body).to.have.property('timeout', timeout); }); it('should set event times', function () { - new Job(mockQueue, type, payload, options); + new Job(mockQueue, type, payload, timeout); const newDoc = validateDoc(mockQueue.client.index); expect(newDoc.body).to.have.property('created'); expect(newDoc.body).to.have.property('started'); @@ -93,13 +80,13 @@ describe('Job Class', function () { }); it('should set attempt count', function () { - new Job(mockQueue, type, payload, options); + new Job(mockQueue, type, payload, timeout); const newDoc = validateDoc(mockQueue.client.index); expect(newDoc.body).to.have.property('attempts'); }); it('should set status as pending', function () { - new Job(mockQueue, type, payload, options); + new Job(mockQueue, type, payload, timeout); const newDoc = validateDoc(mockQueue.client.index); expect(newDoc.body).to.have.property('status', JOB_STATUS_PENDING); });