Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record failed jobs when saving the result fails (dont retry) #28629

Merged
merged 9 commits into from
Jan 23, 2019
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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was the missing piece.


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