From efe51b129e522a9ef170ac05c77dec07a0015af3 Mon Sep 17 00:00:00 2001 From: OldHawk Date: Sat, 26 May 2018 13:33:27 +0800 Subject: [PATCH] feat(invitations): cron jobs to remove all expired user invitations --- config/lib/cron-job.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/config/lib/cron-job.js b/config/lib/cron-job.js index 12e7c97e..74c1e1c5 100644 --- a/config/lib/cron-job.js +++ b/config/lib/cron-job.js @@ -20,6 +20,7 @@ var path = require('path'), UserMonthsLog = mongoose.model('UserMonthsLog'), ScoreLog = mongoose.model('ScoreLog'), Trace = mongoose.model('Trace'), + Invitation = mongoose.model('Invitation'), scoreUpdate = require(path.resolve('./config/lib/score')).update, backup = require('mongodb-backup'); @@ -84,6 +85,7 @@ module.exports = function (app) { cronJobs.push(removeGhostPeers()); cronJobs.push(removeOldServerMessages()); cronJobs.push(removeOldLogData()); + cronJobs.push(removeExpiredUserInvitations()); cronJobs.push(checkUserAccountIdleStatus()); if (hnrConfig.enable) { @@ -269,12 +271,40 @@ function removeOldLogData() { return cronJob; } +/** + * removeExpiredUserInvitations + */ +function removeExpiredUserInvitations() { + var cronJob = new CronJob({ + cronTime: '00 15 1 * * *', + onTick: function () { + logger.info(chalk.green('removeExpiredUserInvitations: process!')); + + //remove announce-log old data + Invitation.remove({ + status: 0, //include exchange and present invitations, official invitations status start of 1 + expiresat: {$lt: Date.now()} + }, function (err) { + if (err) { + logger.error(err); + } + }); + }, + start: false, + timeZone: appConfig.cronTimeZone + }); + + cronJob.start(); + + return cronJob; +} + /** * checkUserAccountIdleStatus */ function checkUserAccountIdleStatus() { var cronJob = new CronJob({ - cronTime: '00 15 1 * * *', + cronTime: '00 20 1 * * *', // cronTime: '*/30 * * * * *', onTick: function () { logger.info(chalk.green('checkUserAccountIdleStatus: process!'));