Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed - Number of attempts reported is now per task and no-longer carried over if chaining error tasks
8 changes: 7 additions & 1 deletion src/lib/queue_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ QueueWorker.prototype._reject = function(taskNumber) {
var id = self.processId + ':' + self.taskNumber;
if (task._state === self.inProgressState &&
task._owner === id) {
var attempts = _.get(task, '_error_details.attempts', 0);
var attempts = 0;
var currentAttempts = _.get(task, '_error_details.attempts', 0);
var currentPrevState = _.get(task, '_error_details.previous_state');
if (currentAttempts > 0 &&
currentPrevState === self.inProgressState) {
attempts = currentAttempts;
}
if (attempts >= self.taskRetries) {
task._state = self.errorState;
} else {
Expand Down
40 changes: 40 additions & 0 deletions test/lib/queue_worker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,46 @@ describe('QueueWorker', function() {
});
});

it('should reject a task owned by the current worker and reset the attempts count if chaning error handlers', function(done) {
qw = new th.QueueWorkerWithoutProcessingOrTimeouts(tasksRef, '0', true, false, _.noop);
qw.setTaskSpec(th.validTaskSpecWithRetries);
testRef = tasksRef.push({
'_state': th.validTaskSpecWithRetries.inProgressState,
'_state_changed': new Date().getTime(),
'_owner': qw.processId + ':' + qw.taskNumber,
'_progress': 0,
'_error_details': {
'previous_state': 'other_in_progress_state',
'attempts': 1
}
}, function(errorA) {
if (errorA) {
return done(errorA);
}
qw.currentTaskRef = testRef;
var initial = true;
testRef.on('value', function(snapshot) {
if (initial) {
initial = false;
qw._reject(qw.taskNumber)();
} else {
try {
var task = snapshot.val();
expect(task).to.have.all.keys(['_progress', '_state_changed', '_error_details']);
expect(task['_state_changed']).to.be.closeTo(new Date().getTime() + th.offset, 250);
expect(task['_progress']).to.equal(0);
expect(task['_error_details']).to.have.all.keys(['previous_state', 'attempts']);
expect(task['_error_details'].previous_state).to.equal(th.validBasicTaskSpec.inProgressState);
expect(task['_error_details'].attempts).to.equal(1);
done();
} catch (errorB) {
done(errorB);
}
}
});
});
});

it('should reject a task owned by the current worker and a non-standard error state', function(done) {
qw = new th.QueueWorkerWithoutProcessingOrTimeouts(tasksRef, '0', true, false, _.noop);
qw.setTaskSpec(th.validTaskSpecWithErrorState);
Expand Down