Skip to content

Commit

Permalink
Record failed ES queue jobs when saving the result fails (don't retry) (
Browse files Browse the repository at this point in the history
  • Loading branch information
joelgriffith authored Jan 23, 2019
1 parent c96068c commit bc86c52
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions x-pack/plugins/reporting/server/lib/esqueue/__tests__/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,33 @@ describe('Worker class', function () {
return sinon.stub(workerWithFailure, '_failJob').returns(Promise.resolve());
}

describe('saving output failure', () => {
it('should mark the job as failed if saving to ES fails', async () => {
const job = {
_id: 'shouldSucced',
_source: {
timeout: 1000,
payload: 'test'
}
};

sinon.stub(mockQueue.client, 'update').returns(Promise.reject({ statusCode: 413 }));

const workerFn = function (jobPayload) {
return new Promise(function (resolve) {
setTimeout(() => resolve(jobPayload), 10);
});
};
const worker = new Worker(mockQueue, 'test', workerFn, defaultWorkerOptions);
const failStub = getFailStub(worker);

await worker._performJob(job);
worker.destroy();

sinon.assert.called(failStub);
});
});

describe('search failure', function () {
it('causes _processPendingJobs to reject the Promise', function () {
sinon.stub(mockQueue.client, 'search').returns(Promise.reject(new Error('test error')));
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/server/lib/esqueue/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export class Worker extends events.EventEmitter {
if (err.statusCode === 409) return false;
this.warn(`Failure saving job output ${job._id}`, err);
this.emit(constants.EVENT_WORKER_JOB_UPDATE_ERROR, this._formatErrorParams(err, job));
return this._failJob(job, (err.message) ? err.message : false);
});
}, (jobErr) => {
if (!jobErr) {
Expand Down

0 comments on commit bc86c52

Please sign in to comment.