modify db.processSortedSet so it works with intervals

This commit is contained in:
Barış Soner Uşaklı
2017-06-23 18:18:34 -04:00
parent b4b68498cd
commit 3d85992757
3 changed files with 32 additions and 24 deletions

View File

@@ -467,13 +467,13 @@ module.exports = function (db, module) {
}
}
module.processSortedSet = function (setKey, process, batch, callback) {
module.processSortedSet = function (setKey, process, options, callback) {
var done = false;
var ids = [];
var cursor = db.collection('objects').find({ _key: setKey })
.sort({ score: 1 })
.project({ _id: 0, value: 1 })
.batchSize(batch);
.batchSize(options.batch);
async.whilst(
function () {
@@ -490,13 +490,20 @@ module.exports = function (db, module) {
ids.push(item.value);
}
if (ids.length < batch && (!done || ids.length === 0)) {
if (ids.length < options.batch && (!done || ids.length === 0)) {
return next(null);
}
process(ids, function (err) {
if (err) {
return next(err);
}
ids = [];
return next(err);
if (options.interval) {
setTimeout(next, options.interval);
} else {
next();
}
});
});
},