using cron to run demo cleanup every day at midnight

This commit is contained in:
orangecoding
2025-09-18 18:04:49 +02:00
parent 28f0a167e6
commit 1d99fc95f7

View File

@@ -1,29 +1,14 @@
import { setInterval } from 'node:timers';
import { removeJobsByUserId } from './storage/jobStorage.js';
import { config } from '../utils.js';
import { getUsers } from './storage/userStorage.js';
import logger from './logger.js';
import cron from 'node-cron';
/**
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
*/
export function cleanupDemoAtMidnight() {
const now = new Date();
const millisUntilMidnightUTC =
(24 - now.getUTCHours()) * 60 * 60 * 1000 -
now.getUTCMinutes() * 60 * 1000 -
now.getUTCSeconds() * 1000 -
now.getUTCMilliseconds();
cleanup();
setTimeout(() => {
setInterval(
() => {
cleanup();
},
24 * 60 * 60 * 1000,
);
}, millisUntilMidnightUTC);
cron.schedule('0 0 * * *', cleanup);
}
function cleanup() {