6
async.retry({times : 25,interval : 30000},myFunction.bind(functionData),function(err,results){
console.log("===================================")
console.log("Async function finished processing")
return;
})

myFunction is called immediately and that too 5 times which is default. also there is no waiting period between calls

Robbie
  • 18,750
  • 4
  • 41
  • 45
Vikas Sharma
  • 67
  • 1
  • 2

2 Answers2

2

This is a version issue I think.

Older versions of async.retry can only be called with a number as the first agument (eg see the v1.2.0 docs)

It does not accept the opts object. So if you pass it in instead of a number for the first argument, it defaults to no interval and a retry count of 5.

I had this same issue using v0.9.0 of the library, updating to v1.4.2 fixed the issue.

James Skinner
  • 623
  • 5
  • 8
0

The retry is dependent on the callback within your function. If the first argument of the callback is not falsy, then it will retry based on your times and interval settings. For example:

var async = require('async');
var count = 0;
var functionData = { some: 'data' };
var myFunction = function(callback, results) {
  console.log(++count);
  process.nextTick(function() {
    if (count < 5) { // Fail 5 times
      return callback({ message: 'this failed' }, null);
    }
    callback(null, { message: 'this succeeded' });
  });
};

async.retry({times : 25, interval : 1000}, myFunction.bind(functionData), function(err, results) {
  console.log("===================================")
  console.log("Async function finished processing")
  return;
});

This outputs:

1
2
3
4
5
===================================
Async function finished processing

With a 1 second interval between each attempt

Robbie
  • 18,750
  • 4
  • 41
  • 45
  • async.retry(opts,function(callback){ console.log("XXXX"); return callback(new Error("sda")); },function(err){ callback(err); }); – Vikas Sharma Sep 12 '15 at 11:00
  • problem is async.retry executes 5 times even when i am using {times : 25, interval : 60000} – Vikas Sharma Sep 12 '15 at 11:08
  • apart from the undefined `callback`, the snippet you pasted in you're 1st comment works as expected for me. I.e. it retries 25 times. – Robbie Sep 12 '15 at 12:53
  • try lowering the interval to test it. maybe your getting a timeout elsewhere after waiting for 5 minutes? – Robbie Sep 12 '15 at 12:54