add completed time and status to failed jobs

with tests
This commit is contained in:
2016-05-02 12:59:23 -07:00
parent b12aa87ad3
commit a143092e64
2 changed files with 27 additions and 0 deletions

View File

@@ -132,7 +132,10 @@ export default class Job extends events.EventEmitter {
throw err;
});
}, (err) => {
const completedTime = moment().toISOString();
const doc = {
status: jobStatuses.JOB_STATUS_FAILED,
completed_at: completedTime,
output: {
content_type: false,
content: err.toString()

View File

@@ -336,6 +336,30 @@ describe('Worker class', function () {
}
});
});
it('should set status to failed', function (done) {
const startTime = moment().valueOf();
const workerFn = function (jobPayload, cb) {
expect(jobPayload).to.eql(payload);
cb(null, payload);
};
const worker = new Worker(mockQueue, 'test', workerFn);
worker._performJob(job)
.then(() => {
try {
sinon.assert.calledOnce(updateSpy);
const doc = updateSpy.firstCall.args[0].body.doc;
expect(doc).to.have.property('status', JOB_STATUS_FAILED);
expect(doc).to.have.property('completed_at');
const completedTimestamp = moment(doc.completed_at).valueOf();
expect(completedTimestamp).to.be.greaterThan(startTime);
done();
} catch (err) {
done(err);
}
});
});
});
});