2025-09-18 15:38:23 +02:00
|
|
|
import { removeJobsByUserId } from './storage/jobStorage.js';
|
2025-05-16 13:20:54 +02:00
|
|
|
import { config } from '../utils.js';
|
|
|
|
|
import { getUsers } from './storage/userStorage.js';
|
2025-09-13 18:57:56 +02:00
|
|
|
import logger from './logger.js';
|
2025-09-18 18:04:49 +02:00
|
|
|
import cron from 'node-cron';
|
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-05-16 13:20:54 +02:00
|
|
|
function cleanup() {
|
|
|
|
|
if (config.demoMode) {
|
|
|
|
|
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-05-16 13:20:54 +02:00
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
}
|