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

@@ -30,17 +30,18 @@ exports.processSortedSet = function (setKey, process, options, callback) {
});
}
options.batch = options.batch || DEFAULT_BATCH_SIZE;
// use the fast path if possible
if (db.processSortedSet && typeof options.doneIf !== 'function' && !utils.isNumber(options.alwaysStartAt)) {
return db.processSortedSet(setKey, process, options.batch || DEFAULT_BATCH_SIZE, callback);
return db.processSortedSet(setKey, process, options, callback);
}
// custom done condition
options.doneIf = typeof options.doneIf === 'function' ? options.doneIf : function () {};
var batch = options.batch || DEFAULT_BATCH_SIZE;
var start = 0;
var stop = batch;
var stop = options.batch;
var done = false;
async.whilst(
@@ -60,8 +61,8 @@ exports.processSortedSet = function (setKey, process, options, callback) {
if (err) {
return next(err);
}
start += utils.isNumber(options.alwaysStartAt) ? options.alwaysStartAt : batch + 1;
stop = start + batch;
start += utils.isNumber(options.alwaysStartAt) ? options.alwaysStartAt : options.batch + 1;
stop = start + options.batch;
if (options.interval) {
setTimeout(next, options.interval);