3 Commits

Author SHA1 Message Date
0bf6fb0023 0.3.2 2016-05-13 14:59:17 -07:00
300449bfb0 add test for missing index result 2016-05-13 14:59:05 -07:00
868c808db7 missing indices need to return an array 2016-05-13 14:56:50 -07:00
3 changed files with 21 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "esqueue", "name": "esqueue",
"version": "0.3.1", "version": "0.3.2",
"description": "Job queue, powered by Elasticsearch", "description": "Job queue, powered by Elasticsearch",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {

View File

@@ -180,7 +180,7 @@ export default class Job extends events.EventEmitter {
} }
_claimPendingJobs(jobs) { _claimPendingJobs(jobs) {
if (jobs.length === 0) return; if (!jobs || jobs.length === 0) return;
this._stopJobPolling(); this._stopJobPolling();
let claimed = false; let claimed = false;
@@ -268,7 +268,7 @@ export default class Job extends events.EventEmitter {
}) })
.catch((err) => { .catch((err) => {
// ignore missing indices errors // ignore missing indices errors
if (err.status === 404) return; if (err.status === 404) return [];
this.debug('job querying failed', err); this.debug('job querying failed', err);
this.emit('error', err); this.emit('error', err);

View File

@@ -165,6 +165,24 @@ describe('Worker class', function () {
.then(() => { done(); }) .then(() => { done(); })
.catch(() => done(new Error('should not reject'))); .catch(() => done(new Error('should not reject')));
}); });
it('should return an empty array on missing index', function (done) {
searchStub = sinon.stub(mockQueue.client, 'search', () => Promise.reject({
status: 404
}));
worker = new Worker(mockQueue, 'test', noop);
worker._getPendingJobs()
.then((res) => {
try {
expect(res).to.be.an(Array);
expect(res).to.have.length(0);
done();
} catch (e) {
done(e);
}
})
.catch(() => done(new Error('should not reject')));
});
}); });
describe('query parameters', function () { describe('query parameters', function () {