Created
June 3, 2014 01:25
-
-
Save johnnyhalife/947ffc7d81ee38892cb3 to your computer and use it in GitHub Desktop.
This file contains 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 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