diff --git a/src/helpers/constants.js b/src/helpers/constants.js new file mode 100644 index 0000000..0faec5f --- /dev/null +++ b/src/helpers/constants.js @@ -0,0 +1,7 @@ +const constants = { + JOB_STATUS_PENDING: 0, + JOB_STATUS_PROCESSING: 1, + JOB_STATUS_COMPLETED: 2, +}; + +export default constants; diff --git a/src/job.js b/src/job.js index 5f65d1f..d7f644f 100644 --- a/src/job.js +++ b/src/job.js @@ -1,7 +1,6 @@ import events from 'events'; import { isPlainObject, omit } from 'lodash'; - -const PENDING = 0; +import { JOB_STATUS_PENDING } from './helpers/constants'; export default class Job extends events.EventEmitter { constructor(queue, type, payload, options = {}) { @@ -15,7 +14,7 @@ export default class Job extends events.EventEmitter { this.payload = payload; this.timeout = options.timeout || 10000; this.options = omit(options, [ 'timeout' ]); - this.status = PENDING; + this.status = JOB_STATUS_PENDING; this.ready = this.queue.client.index({ index: this.queue.index, @@ -28,7 +27,7 @@ export default class Job extends events.EventEmitter { started: null, completed: null, attempts: 0, - status: PENDING, + status: this.status, } }) .then((doc) => { diff --git a/test/src/job.js b/test/src/job.js index 67401d2..8bbca08 100644 --- a/test/src/job.js +++ b/test/src/job.js @@ -4,6 +4,7 @@ import sinon from 'sinon'; import _ from 'lodash'; import Job from '../../lib/job'; import * as elasticsearchMock from '../fixtures/elasticsearch'; +import { JOB_STATUS_PENDING } from '../../lib/helpers/constants'; describe('Job Class', function () { let mockQueue; @@ -100,7 +101,7 @@ describe('Job Class', function () { it('should set status as pending', function () { new Job(mockQueue, type, payload, options); const newDoc = validateDoc(mockQueue.client.index); - expect(newDoc.body).to.have.property('status', PENDING); + expect(newDoc.body).to.have.property('status', JOB_STATUS_PENDING); }); }); });