Archived
2

changelog delete

This commit is contained in:
VLE2FE
2020-08-31 16:20:22 +02:00
parent 8f88023da2
commit d28e9a1cc9
3 changed files with 32 additions and 13 deletions

View File

@ -2,12 +2,14 @@ import mongoose from 'mongoose';
import cfenv from 'cfenv';
import _ from 'lodash';
import ChangelogModel from './models/changelog';
import cron from 'node-cron';
// database urls, prod db url is retrieved automatically
const TESTING_URL = 'mongodb://localhost/dfopdb_test';
const DEV_URL = 'mongodb://localhost/dfopdb';
const debugging = true;
const changelogKeepDays = 30; // days to keep the changelog
if (process.env.NODE_ENV !== 'production' && debugging) {
mongoose.set('debug', true); // enable mongoose debug
@ -78,6 +80,16 @@ export default class db {
this.state.db = mongoose.connection;
done();
});
if (mode !== 'test') { // clear old changelog regularly
cron.schedule('0 0 * * *', () => {
ChangelogModel.deleteMany({_id: {$lt: // id from time
Math.floor(new Date().getTime() / 1000 - changelogKeepDays * 24 * 60 * 60).toString(16) + '0000000000000000'
}}).log({method: 'scheduled changelog delete', url: '', authDetails: {}}).lean().exec(err => {
if (err) console.error(err);
});
});
}
}
static disconnect (done) {