cleaner plugin: manual tests OK
This commit is contained in:
parent
a9f65adb77
commit
9f1da23e45
|
@ -130,6 +130,9 @@ MessageDb.prototype.getAll = function(cb) {
|
|||
.on('data', function(data) {
|
||||
list.push(MessageDb.fromStorage(data));
|
||||
})
|
||||
.on('error', function(err) {
|
||||
return cb(err);
|
||||
})
|
||||
.on('end', function() {
|
||||
return cb(null, list);
|
||||
});
|
||||
|
@ -144,12 +147,16 @@ MessageDb.prototype.removeUpTo = function(ts, cb) {
|
|||
.on('data', function(key) {
|
||||
var parsed = MessageDb.parseKey(key);
|
||||
if (parsed.ts < ts) {
|
||||
logger.verbose('Deleting message ' + key);
|
||||
dels.push({
|
||||
type: 'del',
|
||||
key: key
|
||||
});
|
||||
}
|
||||
})
|
||||
.on('error', function(err) {
|
||||
return cb(err);
|
||||
})
|
||||
.on('end', function() {
|
||||
db.batch(dels, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
|
|
@ -7,16 +7,19 @@ var CronJob = cron.CronJob;
|
|||
|
||||
|
||||
module.exports.init = function(config) {
|
||||
logger.info('Using cleaner plugin');
|
||||
logger.info(config);
|
||||
var cronTime = config.cronTime || '0 * * * *';
|
||||
logger.info('Using cleaner plugin with cronTime ' + cronTime);
|
||||
var onTick = function() {
|
||||
var limit = microtime.now() - 1000 * 1000 * config.threshold;
|
||||
mdb.removeUpTo(limit, function(err, n) {
|
||||
if (err) logger.error(err);
|
||||
else logger.info('Ran cleaner task, removed ' + n);
|
||||
});
|
||||
};
|
||||
var job = new CronJob({
|
||||
cronTime: config.cronTime || '0 * * * *',
|
||||
onTick: function() {
|
||||
var limit = microtime.now() - 1000 * 1000 * config.threshold;
|
||||
mdb.removeUpTo(limit, function(err, n) {
|
||||
logger.verbose('Ran cleaner task, removed ' + n);
|
||||
});
|
||||
},
|
||||
start: true
|
||||
cronTime: cronTime,
|
||||
onTick: onTick
|
||||
});
|
||||
onTick();
|
||||
job.start();
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
|
||||
cronTime: '* * * * *',
|
||||
threshold: 10, // in seconds
|
||||
threshold: 2*24*60*60, // 2 days, in seconds
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue