correction to monitor opendock activation

This commit is contained in:
2026-03-11 16:23:04 -05:00
parent 4f24fe4660
commit bf7d765989
5 changed files with 41 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
import { systemSettings } from "backend/server.js";
import { io, type Socket } from "socket.io-client"; import { io, type Socket } from "socket.io-client";
import { createLogger } from "../logger/logger.controller.js"; import { createLogger } from "../logger/logger.controller.js";
import { getToken, odToken } from "./opendock.utils.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; const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;
let socket: Socket | null = null; let socket: Socket | null = null;
export const opendockSocketMonitor = async () => { 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) { if (!odToken.odToken) {
log.info({}, "Getting Auth Token"); log.info({}, "Getting Auth Token");
await getToken(); await getToken();

View File

@@ -1,7 +1,9 @@
import { createServer } from "node:http"; import { createServer } from "node:http";
import os from "node:os"; import os from "node:os";
import createApp from "./app.js"; import createApp from "./app.js";
import { db } from "./db/db.controller.js";
import { dbCleanup } from "./db/dbCleanup.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 { createLogger } from "./logger/logger.controller.js";
import { monitorReleaseChanges } from "./opendock/openDockRreleaseMonitor.utils.js"; import { monitorReleaseChanges } from "./opendock/openDockRreleaseMonitor.utils.js";
import { opendockSocketMonitor } from "./opendock/opendockSocketMonitor.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"; import { createCronJob } from "./utils/croner.utils.js";
const port = Number(process.env.PORT) || 3000; const port = Number(process.env.PORT) || 3000;
export let systemSettings: Setting[] = [];
const start = async () => { const start = async () => {
const log = createLogger({ module: "system", subModule: "main start" }); 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 // trigger startup processes these must run before anything else can run
await baseSettingValidationCheck(); await baseSettingValidationCheck();
systemSettings = await db.select().from(settings);
//when starting up long lived features the name must match the setting name. //when starting up long lived features the name must match the setting name.
setTimeout(() => { setTimeout(() => {
monitorReleaseChanges(); // this is od monitoring the db for all new releases if (systemSettings.filter((n) => n.name === "opendock_sync")[0]?.active) {
opendockSocketMonitor(); 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 // cleanup sql jobs
createCronJob("JobAuditLogCleanUp", "0 0 5 * * *", () => createCronJob("JobAuditLogCleanUp", "0 0 5 * * *", () =>
dbCleanup("jobs", 30), dbCleanup("jobs", 30),
); );
createCronJob("logsCleanup", "0 15 5 * * *", () => dbCleanup("logs", 120)); createCronJob("logsCleanup", "0 15 5 * * *", () => dbCleanup("logs", 120));
createCronJob("opendockAptCleanup", "0 30 5 * * *", () =>
dbCleanup("opendockApt", 90),
);
}, 5 * 1000); }, 5 * 1000);
const { app, baseUrl } = await createApp(); const { app, baseUrl } = await createApp();

View File

@@ -43,9 +43,4 @@ export const setupSocketIORoutes = (baseUrl: string, server: HttpServer) => {
auth: false, auth: false,
//namespaceName: "/admin", //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.
}; };

View File

@@ -3,8 +3,18 @@
* we will stop jobs, stop cycles * we will stop jobs, stop cycles
*/ */
import { dbCleanup } from "../db/dbCleanup.controller.js";
import type { Setting } from "../db/schema/settings.schema.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) => { export const featureControl = async (data: Setting) => {
// when a feature is changed to active or deactivated we will update the cron. // 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 { } else {
stopCronJob(data.name); stopCronJob(data.name);
} }
if (data.name === "opendock_sync" && data.active) {
opendockSocketMonitor();
monitorReleaseChanges();
createCronJob("opendockAptCleanup", "0 30 5 * * *", () =>
dbCleanup("opendockApt", 90),
);
} else {
killOpendockSocket();
stopCronJob("opendockAptCleanup");
}
}; };

View File

@@ -1,4 +1,3 @@
vars { vars {
url: http://usmcd1vms036:3100 url: http://localhost:3000/lst
~session_cookie:
} }