correction to monitor opendock activation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { systemSettings } from "backend/server.js";
|
||||
import { io, type Socket } from "socket.io-client";
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
import { getToken, odToken } from "./opendock.utils.js";
|
||||
@@ -6,6 +7,11 @@ const log = createLogger({ module: "opendock", subModule: "releaseMonitor" });
|
||||
const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;
|
||||
let socket: Socket | null = null;
|
||||
export const opendockSocketMonitor = async () => {
|
||||
// checking if we actaully want to run this
|
||||
if (!systemSettings.filter((n) => n.name === "opendock_sync")[0]?.active) {
|
||||
log.info({}, "Opendock is not active");
|
||||
}
|
||||
|
||||
if (!odToken.odToken) {
|
||||
log.info({}, "Getting Auth Token");
|
||||
await getToken();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { createServer } from "node:http";
|
||||
import os from "node:os";
|
||||
import createApp from "./app.js";
|
||||
import { db } from "./db/db.controller.js";
|
||||
import { dbCleanup } from "./db/dbCleanup.controller.js";
|
||||
import { type Setting, settings } from "./db/schema/settings.schema.js";
|
||||
import { createLogger } from "./logger/logger.controller.js";
|
||||
import { monitorReleaseChanges } from "./opendock/openDockRreleaseMonitor.utils.js";
|
||||
import { opendockSocketMonitor } from "./opendock/opendockSocketMonitor.utils.js";
|
||||
@@ -11,7 +13,7 @@ import { baseSettingValidationCheck } from "./system/settingsBase.controller.js"
|
||||
import { createCronJob } from "./utils/croner.utils.js";
|
||||
|
||||
const port = Number(process.env.PORT) || 3000;
|
||||
|
||||
export let systemSettings: Setting[] = [];
|
||||
const start = async () => {
|
||||
const log = createLogger({ module: "system", subModule: "main start" });
|
||||
|
||||
@@ -20,20 +22,24 @@ const start = async () => {
|
||||
|
||||
// trigger startup processes these must run before anything else can run
|
||||
await baseSettingValidationCheck();
|
||||
systemSettings = await db.select().from(settings);
|
||||
|
||||
//when starting up long lived features the name must match the setting name.
|
||||
setTimeout(() => {
|
||||
monitorReleaseChanges(); // this is od monitoring the db for all new releases
|
||||
opendockSocketMonitor();
|
||||
if (systemSettings.filter((n) => n.name === "opendock_sync")[0]?.active) {
|
||||
log.info({}, "Opendock is not active");
|
||||
monitorReleaseChanges(); // this is od monitoring the db for all new releases
|
||||
opendockSocketMonitor();
|
||||
createCronJob("opendockAptCleanup", "0 30 5 * * *", () =>
|
||||
dbCleanup("opendockApt", 90),
|
||||
);
|
||||
}
|
||||
|
||||
// cleanup sql jobs
|
||||
createCronJob("JobAuditLogCleanUp", "0 0 5 * * *", () =>
|
||||
dbCleanup("jobs", 30),
|
||||
);
|
||||
createCronJob("logsCleanup", "0 15 5 * * *", () => dbCleanup("logs", 120));
|
||||
createCronJob("opendockAptCleanup", "0 30 5 * * *", () =>
|
||||
dbCleanup("opendockApt", 90),
|
||||
);
|
||||
}, 5 * 1000);
|
||||
|
||||
const { app, baseUrl } = await createApp();
|
||||
|
||||
@@ -43,9 +43,4 @@ export const setupSocketIORoutes = (baseUrl: string, server: HttpServer) => {
|
||||
auth: false,
|
||||
//namespaceName: "/admin",
|
||||
});
|
||||
//setup all the routes
|
||||
// app.use(`${baseUrl}/api/datamart`, runQuery);
|
||||
// app.use(`${baseUrl}/api/datamart`, addQuery);
|
||||
// app.use(`${baseUrl}/api/datamart`, updateQuery);
|
||||
// just sending a get on datamart will return all the queries that we can call.
|
||||
};
|
||||
|
||||
@@ -3,8 +3,18 @@
|
||||
* we will stop jobs, stop cycles
|
||||
*/
|
||||
|
||||
import { dbCleanup } from "../db/dbCleanup.controller.js";
|
||||
import type { Setting } from "../db/schema/settings.schema.js";
|
||||
import { resumeCronJob, stopCronJob } from "../utils/croner.utils.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.
|
||||
@@ -13,4 +23,15 @@ export const featureControl = async (data: Setting) => {
|
||||
} 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");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
vars {
|
||||
url: http://usmcd1vms036:3100
|
||||
~session_cookie:
|
||||
url: http://localhost:3000/lst
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user