Files
lst_v3/backend/system/settingsFeatures.controller.ts

38 lines
1020 B
TypeScript

/**
* When a feature setting gets updated we will handle it here.
* we will stop jobs, stop cycles
*/
import { dbCleanup } from "../db/dbCleanup.controller.js";
import type { Setting } from "../db/schema/settings.schema.js";
import { monitorReleaseChanges } from "../opendock/openDockRreleaseMonitor.utils.js";
import {
killOpendockSocket,
opendockSocketMonitor,
} from "../opendock/opendockSocketMonitor.utils.js";
import {
createCronJob,
resumeCronJob,
stopCronJob,
} from "../utils/croner.utils.js";
export const featureControl = async (data: Setting) => {
// when a feature is changed to active or deactivated we will update the cron.
if (data.active) {
resumeCronJob(data.name);
} else {
stopCronJob(data.name);
}
if (data.name === "opendock_sync" && data.active) {
opendockSocketMonitor();
monitorReleaseChanges();
createCronJob("opendockAptCleanup", "0 30 5 * * *", () =>
dbCleanup("opendockApt", 90),
);
} else {
killOpendockSocket();
stopCronJob("opendockAptCleanup");
}
};