add check for failed status and complete time
This commit is contained in:
@@ -131,14 +131,14 @@ export default class Job extends events.EventEmitter {
|
||||
if (err.statusCode === 409) return false;
|
||||
throw err;
|
||||
});
|
||||
}, (err) => {
|
||||
}, (jobErr) => {
|
||||
const completedTime = moment().toISOString();
|
||||
const doc = {
|
||||
status: jobStatuses.JOB_STATUS_FAILED,
|
||||
completed_at: completedTime,
|
||||
output: {
|
||||
content_type: false,
|
||||
content: err.toString()
|
||||
content: jobErr.toString()
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,7 +150,7 @@ export default class Job extends events.EventEmitter {
|
||||
body: { doc }
|
||||
})
|
||||
.catch(() => false)
|
||||
.then(() => { throw err; });
|
||||
.then(() => { throw jobErr; });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -305,8 +305,8 @@ describe('Worker class', function () {
|
||||
|
||||
worker._performJob(job)
|
||||
.then(() => done(new Error('should not resolve')))
|
||||
.catch((err) => {
|
||||
expect(err.message).to.equal('test error');
|
||||
.catch((e) => {
|
||||
expect(e.message).to.equal('test error');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -337,16 +337,16 @@ describe('Worker class', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should set status to failed', function (done) {
|
||||
it('should set completed time and status to failed', function (done) {
|
||||
const startTime = moment().valueOf();
|
||||
const workerFn = function (jobPayload, cb) {
|
||||
expect(jobPayload).to.eql(payload);
|
||||
cb(null, payload);
|
||||
cb(new Error('test error'));
|
||||
};
|
||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||
|
||||
worker._performJob(job)
|
||||
.then(() => {
|
||||
.then(() => done(new Error('should not resolve')))
|
||||
.catch(() => {
|
||||
try {
|
||||
sinon.assert.calledOnce(updateSpy);
|
||||
const doc = updateSpy.firstCall.args[0].body.doc;
|
||||
@@ -355,8 +355,8 @@ describe('Worker class', function () {
|
||||
const completedTimestamp = moment(doc.completed_at).valueOf();
|
||||
expect(completedTimestamp).to.be.greaterThan(startTime);
|
||||
done();
|
||||
} catch (err) {
|
||||
done(err);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user