Skip to content

Instantly share code, notes, and snippets.

@johnnyhalife
Created June 3, 2014 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnnyhalife/947ffc7d81ee38892cb3 to your computer and use it in GitHub Desktop.
Save johnnyhalife/947ffc7d81ee38892cb3 to your computer and use it in GitHub Desktop.
var fetched = 0, step = 100, skip = 0;
var queueName = 'operations';
var queueService = azure.createQueueService().withFilter(new azure.ExponentialRetryPolicyFilter());
async.doWhilst(function(allDone){
getDb(function(db) { // traes la conexión a mongo
getQueue(queueName, function(err) { // traes la cola
if(err) allDone(err);
var criteria = { }; // haces el query
// fijate que traigo de a 100 records
db.collection('tu_table').find(criteria).limit(step).skip(skip).toArray(function(err, results) {
if(err) throw err; // manejar no tirar el error
// de a 50 en paraleloo como máximo
async.eachLimit(results, 50, myFuncion /** llamas a la funcion que encola o algo asi */, function(err) {
skip += (fetched = profiles.length);
console.log("[%s] Enqueued %s messages so far", new Date(), skip);
allDone(err);
});
});
});
});
}, function(){ return fetched != 0; }, function(err) { // vas hasta que el query te de cero.
console.log("[%s] Completed process for Daily Digest", new Date().toString());
process.exit(0);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment