add check for failed status and complete time

This commit is contained in:
2016-05-02 14:31:14 -07:00
parent a143092e64
commit 60d486b804
2 changed files with 11 additions and 11 deletions

View File

@@ -131,14 +131,14 @@ export default class Job extends events.EventEmitter {
if (err.statusCode === 409) return false; if (err.statusCode === 409) return false;
throw err; throw err;
}); });
}, (err) => { }, (jobErr) => {
const completedTime = moment().toISOString(); const completedTime = moment().toISOString();
const doc = { const doc = {
status: jobStatuses.JOB_STATUS_FAILED, status: jobStatuses.JOB_STATUS_FAILED,
completed_at: completedTime, completed_at: completedTime,
output: { output: {
content_type: false, content_type: false,
content: err.toString() content: jobErr.toString()
} }
}; };
@@ -150,7 +150,7 @@ export default class Job extends events.EventEmitter {
body: { doc } body: { doc }
}) })
.catch(() => false) .catch(() => false)
.then(() => { throw err; }); .then(() => { throw jobErr; });
}); });
} }

View File

@@ -305,8 +305,8 @@ describe('Worker class', function () {
worker._performJob(job) worker._performJob(job)
.then(() => done(new Error('should not resolve'))) .then(() => done(new Error('should not resolve')))
.catch((err) => { .catch((e) => {
expect(err.message).to.equal('test error'); expect(e.message).to.equal('test error');
done(); 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 startTime = moment().valueOf();
const workerFn = function (jobPayload, cb) { const workerFn = function (jobPayload, cb) {
expect(jobPayload).to.eql(payload); cb(new Error('test error'));
cb(null, payload);
}; };
const worker = new Worker(mockQueue, 'test', workerFn); const worker = new Worker(mockQueue, 'test', workerFn);
worker._performJob(job) worker._performJob(job)
.then(() => { .then(() => done(new Error('should not resolve')))
.catch(() => {
try { try {
sinon.assert.calledOnce(updateSpy); sinon.assert.calledOnce(updateSpy);
const doc = updateSpy.firstCall.args[0].body.doc; const doc = updateSpy.firstCall.args[0].body.doc;
@@ -355,8 +355,8 @@ describe('Worker class', function () {
const completedTimestamp = moment(doc.completed_at).valueOf(); const completedTimestamp = moment(doc.completed_at).valueOf();
expect(completedTimestamp).to.be.greaterThan(startTime); expect(completedTimestamp).to.be.greaterThan(startTime);
done(); done();
} catch (err) { } catch (e) {
done(err); done(e);
} }
}); });
}); });