Merge pull request #1106 from alolis/reset-fields-on-job-retry

Reset 'failedReason', 'finishedOn' and 'processedOn' fields on job retry
This commit is contained in:
Manuel Astudillo
2018-10-27 14:08:08 +02:00
committed by GitHub
2 changed files with 36 additions and 13 deletions
+25 -12
View File
@@ -315,18 +315,31 @@ Job.prototype.promote = function() {
Job.prototype.retry = function() {
var _this = this;
return this.queue.isReady().then(function() {
return scripts
.reprocessJob(_this, { state: 'failed' })
.then(function(result) {
if (result === 1) {
return;
} else if (result === 0) {
throw new Error(errors.Messages.RETRY_JOB_NOT_EXIST);
} else if (result === -1) {
throw new Error(errors.Messages.RETRY_JOB_IS_LOCKED);
} else if (result === -2) {
throw new Error(errors.Messages.RETRY_JOB_NOT_FAILED);
}
_this.failedReason = null;
_this.finishedOn = null;
_this.processedOn = null;
return _this.queue.client
.hdel(
_this.queue.toKey(_this.id),
'finishedOn',
'processedOn',
'failedReason'
)
.then(function(redisResult) {
return scripts
.reprocessJob(_this, { state: 'failed' })
.then(function(result) {
if (result === 1) {
return;
} else if (result === 0) {
throw new Error(errors.Messages.RETRY_JOB_NOT_EXIST);
} else if (result === -1) {
throw new Error(errors.Messages.RETRY_JOB_IS_LOCKED);
} else if (result === -2) {
throw new Error(errors.Messages.RETRY_JOB_NOT_FAILED);
}
});
});
});
};
+11 -1
View File
@@ -1411,7 +1411,17 @@ describe('Queue', function() {
expect(job.data.foo).to.be.eql('bar');
expect(err).to.be.eql(notEvenErr);
failedOnce = true;
job.retry();
job.retry().then(function() {
expect(job.failedReason).to.be.null;
expect(job.processedOn).to.be.null;
expect(job.finishedOn).to.be.null;
retryQueue.getJob(job.id).then(function(updatedJob) {
expect(updatedJob.failedReason).to.be.undefined;
expect(updatedJob.processedOn).to.be.undefined;
expect(updatedJob.finishedOn).to.be.undefined;
});
});
});
retryQueue.once('completed', function() {