2025-09-22 09:57:50 +02:00
|
|
|
import { removeJobsByUserId } from '../storage/jobStorage.js';
|
|
|
|
|
import { getUsers } from '../storage/userStorage.js';
|
|
|
|
|
import logger from '../logger.js';
|
2025-09-18 18:04:49 +02:00
|
|
|
import cron from 'node-cron';
|
2025-12-09 13:56:46 +01:00
|
|
|
import { getSettings } from '../storage/settingsStorage.js';
|
2024-11-22 09:11:10 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
|
|
|
|
|
*/
|
|
|
|
|
export function cleanupDemoAtMidnight() {
|
2025-09-18 18:04:49 +02:00
|
|
|
cron.schedule('0 0 * * *', cleanup);
|
2024-11-22 09:11:10 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-09 13:56:46 +01:00
|
|
|
async function cleanup() {
|
|
|
|
|
const settings = await getSettings();
|
|
|
|
|
if (settings.demoMode) {
|
2025-05-16 13:20:54 +02:00
|
|
|
const demoUser = getUsers(false).find((user) => user.username === 'demo');
|
|
|
|
|
if (demoUser == null) {
|
2025-09-13 18:57:56 +02:00
|
|
|
logger.error('Demo user not found, cannot remove Jobs');
|
2025-12-09 13:56:46 +01:00
|
|
|
return Promise.resolve();
|
2024-11-22 09:11:10 +01:00
|
|
|
}
|
2025-09-18 15:38:23 +02:00
|
|
|
removeJobsByUserId(demoUser.id);
|
2025-05-16 13:20:54 +02:00
|
|
|
}
|
|
|
|
|
}
|