From 1d99fc95f7330b926711a184503bc574858011a9 Mon Sep 17 00:00:00 2001 From: orangecoding Date: Thu, 18 Sep 2025 18:04:49 +0200 Subject: [PATCH] using cron to run demo cleanup every day at midnight --- lib/services/demoCleanup.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/services/demoCleanup.js b/lib/services/demoCleanup.js index b5e865a..b21d383 100644 --- a/lib/services/demoCleanup.js +++ b/lib/services/demoCleanup.js @@ -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() {