mirror of
https://github.com/OptimalBits/bull.git
synced 2026-07-02 00:17:41 +08:00
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:
+25
-12
@@ -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
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user