Last active
December 14, 2015 01:39
-
-
Save sintaxi/5007744 to your computer and use it in GitHub Desktop.
Async compatible Batch and Retry api requirements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var batcher = require("batcher") | |
var myUploader = function(item, done){ | |
uploadSomewhere(item, function(err, result){ | |
done(err, result) | |
}) | |
} | |
var myErrCheck = function(err, retry, pass){ | |
if(err.statusCode == 503){ | |
retry() | |
}else{ | |
pass() | |
} | |
} | |
batcher.batch(["item1", "item2", "item3"], myUploader, { batchSize: 4, errFn: myErrCheck }, function(err, results){ | |
if(err){ | |
// we failed even after retrys | |
}else{ | |
// all tasks are successful | |
} | |
}) | |
It appears that async's eachLimit()
is half of what we want. Just need to build an array of items to retry.
https://github.com/caolan/async#eachlimitarr-limit-iterator-callback
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Third argument should be optional in which case it would default to batch size of
4
and perform no retries.Third argument could also be a
function
in which case the batch size would default to4
.Third argument could also be an
integer
in which case the batch size would change to value passed in and no retries would be performed.