mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
fixing removing demo jobs
This commit is contained in:
@@ -1,29 +1,38 @@
|
|||||||
import { setInterval } from 'node:timers';
|
import { setInterval } from 'node:timers';
|
||||||
import {removeJobsByUserName} from './storage/jobStorage.js';
|
import { removeJobsByUserName } from './storage/jobStorage.js';
|
||||||
import {config} from '../utils.js';
|
import { config } from '../utils.js';
|
||||||
|
import { getUsers } from './storage/userStorage.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
|
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
|
||||||
*/
|
*/
|
||||||
export function cleanupDemoAtMidnight() {
|
export function cleanupDemoAtMidnight() {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const millisUntilMidnightUTC = (24 - now.getUTCHours()) * 60 * 60 * 1000
|
const millisUntilMidnightUTC =
|
||||||
- now.getUTCMinutes() * 60 * 1000
|
(24 - now.getUTCHours()) * 60 * 60 * 1000 -
|
||||||
- now.getUTCSeconds() * 1000
|
now.getUTCMinutes() * 60 * 1000 -
|
||||||
- now.getUTCMilliseconds();
|
now.getUTCSeconds() * 1000 -
|
||||||
|
now.getUTCMilliseconds();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
setInterval(
|
||||||
|
() => {
|
||||||
cleanup();
|
cleanup();
|
||||||
|
},
|
||||||
setInterval(() => {
|
24 * 60 * 60 * 1000,
|
||||||
cleanup();
|
);
|
||||||
}, 24 * 60 * 60 * 1000);
|
}, millisUntilMidnightUTC);
|
||||||
|
|
||||||
}, millisUntilMidnightUTC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup(){
|
function cleanup() {
|
||||||
if(config.demoMode){
|
if (config.demoMode) {
|
||||||
removeJobsByUserName('demo');
|
const demoUser = getUsers(false).find((user) => user.username === 'demo');
|
||||||
|
if (demoUser == null) {
|
||||||
|
console.error('Demo user not found, cannot remove Jobs');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
removeJobsByUserName(demoUser.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ const db = new LowdashAdapter(adapter, { jobs: [] });
|
|||||||
|
|
||||||
db.read();
|
db.read();
|
||||||
|
|
||||||
|
|
||||||
export const upsertJob = ({ jobId, name, blacklist = [], enabled = true, provider, notificationAdapter, userId }) => {
|
export const upsertJob = ({ jobId, name, blacklist = [], enabled = true, provider, notificationAdapter, userId }) => {
|
||||||
const currentJob =
|
const currentJob =
|
||||||
jobId == null
|
jobId == null
|
||||||
@@ -77,15 +76,15 @@ export const removeJobsByUserId = (userId) => {
|
|||||||
.value();
|
.value();
|
||||||
db.write();
|
db.write();
|
||||||
};
|
};
|
||||||
export const removeJobsByUserName = (userName) => {
|
export const removeJobsByUserName = (userId) => {
|
||||||
db.chain
|
db.chain
|
||||||
.get('jobs')
|
.get('jobs')
|
||||||
.filter((job) => job.username === userName)
|
.filter((job) => job.userId === userId)
|
||||||
.forEach((job) => listingStorage.removeListings(job.id));
|
.forEach((job) => listingStorage.removeListings(job.id));
|
||||||
db.chain
|
db.chain
|
||||||
.get('jobs')
|
.get('jobs')
|
||||||
.remove((job) => job.username === userName)
|
.remove((job) => job.userId === userId)
|
||||||
.value();
|
.value();
|
||||||
db.write();
|
db.write();
|
||||||
};
|
};
|
||||||
export const getJobs = () => {
|
export const getJobs = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user