{"size": 753, "ext": "js", "max_stars_repo_path": "plugins/cleaner.js", "max_stars_repo_name": "Jenova7/Electrasight-API", "max_stars_repo_stars_event_min_datetime": "2015-01-18T15:52:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-29T06:43:08.000Z", "max_issues_repo_path": "plugins/cleaner.js", "max_issues_repo_name": "Jenova7/Electrasight-API", "max_issues_repo_issues_event_min_datetime": "2018-01-19T22:17:52.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-30T06:02:01.000Z", "max_forks_repo_path": "plugins/cleaner.js", "max_forks_repo_name": "Jenova7/Electrasight-API", "max_forks_repo_forks_event_min_datetime": "2015-01-17T00:24:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-27T20:27:02.000Z"}
{"max_stars_count": 7, "max_issues_count": 3, "max_forks_count": 14, "avg_line_length": 28.9615384615, "max_line_length": 65, "alphanum_fraction": 0.6414342629}
var mdb = require('../lib/MessageDb').default();
var logger = require('../lib/logger').logger;
var preconditions = require('preconditions').singleton();
var microtime = require('microtime');
var cron = require('cron');
var CronJob = cron.CronJob;


module.exports.init = function(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: cronTime,
    onTick: onTick
  });
  onTick();
  job.start();
};
