Skip to content

Commit

Permalink
Merge pull request #984 from nwhatt/master
Browse files Browse the repository at this point in the history
Add delay to custom back off function
  • Loading branch information
behrad authored Dec 23, 2016
2 parents 2691399 + daa9387 commit c1ce220
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Job retry attempts are done as soon as they fail, with no delay, even if your jo

// Use a function to get a customized next attempt delay value
job.attempts(3).backoff( function( attempts, delay ){
//attempts will correspond to the nth attempt failure so it will start with 0
//delay will be the amount of the last delay, not the initial delay unless attempts === 0
return my_customized_calculated_delay;
})
```
Expand Down
2 changes: 1 addition & 1 deletion lib/queue/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ Job.prototype.reattempt = function( attempts, clbk ) {
var delay = this.delay();
if( _.isFunction(this._getBackoffImpl()) ) {
try {
delay = this._getBackoffImpl().apply(this, [ attempts ]);
delay = this._getBackoffImpl().apply(this, [ attempts, delay ]);
} catch(e) {
clbk(e);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe 'Kue Tests', ->
[total, remaining] = [2,2]
start = Date.now()
jobs.create( 'backoff-user-job', { title: 'backoff-user-job' } )
.delay( 50 ).attempts(total).backoff( ( attempts ) -> 250 ).save()
.delay( 50 ).attempts(total).backoff( ( attempts, delay ) -> 250 ).save()
jobs.process 'backoff-user-job', (job, jdone) ->
now = Date.now()
if( !--remaining )
Expand Down

0 comments on commit c1ce220

Please # to comment.