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