feat(update all): added a new function to update all servers in a row. easier to walk away
This commit is contained in:
@@ -12,7 +12,8 @@ type UpdateServerResponse = {
|
|||||||
|
|
||||||
export const updateServer = async (
|
export const updateServer = async (
|
||||||
devApp: string,
|
devApp: string,
|
||||||
server: string | null
|
server: string | null,
|
||||||
|
all?: boolean | null
|
||||||
): Promise<UpdateServerResponse> => {
|
): Promise<UpdateServerResponse> => {
|
||||||
const app = await getAppInfo(devApp);
|
const app = await getAppInfo(devApp);
|
||||||
const serverInfo = await db
|
const serverInfo = await db
|
||||||
@@ -34,7 +35,7 @@ export const updateServer = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverInfo[0].isUpgrading) {
|
if (serverInfo[0].isUpgrading && !all) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"lst",
|
"lst",
|
||||||
@@ -165,6 +166,9 @@ export const updateServer = async (
|
|||||||
export async function processAllServers(devApp: string) {
|
export async function processAllServers(devApp: string) {
|
||||||
const servers = await db.select().from(serverData);
|
const servers = await db.select().from(serverData);
|
||||||
|
|
||||||
|
//change all servers to be upgrading
|
||||||
|
await db.update(serverData).set({ isUpgrading: true });
|
||||||
|
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
"lst",
|
"lst",
|
||||||
@@ -176,7 +180,8 @@ export async function processAllServers(devApp: string) {
|
|||||||
try {
|
try {
|
||||||
const updateToServer = await updateServer(
|
const updateToServer = await updateServer(
|
||||||
devApp,
|
devApp,
|
||||||
server.plantToken
|
server.plantToken,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
@@ -186,7 +191,11 @@ export async function processAllServers(devApp: string) {
|
|||||||
);
|
);
|
||||||
count = count + 1;
|
count = count + 1;
|
||||||
|
|
||||||
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
|
// return {
|
||||||
|
// success: true,
|
||||||
|
// message: `${server.sName} was updated.`,
|
||||||
|
// data: updateToServer,
|
||||||
|
// };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
"info",
|
||||||
@@ -194,7 +203,15 @@ export async function processAllServers(devApp: string) {
|
|||||||
"serverUpdater",
|
"serverUpdater",
|
||||||
`Error updating ${server.sName}: ${error.message}`
|
`Error updating ${server.sName}: ${error.message}`
|
||||||
);
|
);
|
||||||
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
// return {
|
||||||
|
// success: false,
|
||||||
|
// message: `Error updating ${server.sName}: ${error.message}`,
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `All Servers are being updated this will take some time.`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import {updateServer} from "../../../../scripts/updateServers.js";
|
import {
|
||||||
|
processAllServers,
|
||||||
|
updateServer,
|
||||||
|
} from "../../../../scripts/updateServers.js";
|
||||||
|
|
||||||
// Define the request body schema
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
@@ -13,26 +16,33 @@ const requestSchema = z.object({
|
|||||||
// Define the response schema
|
// Define the response schema
|
||||||
const responseSchema = z.object({
|
const responseSchema = z.object({
|
||||||
message: z.string().optional(),
|
message: z.string().optional(),
|
||||||
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
module_id: z
|
||||||
name: z.string().openapi({example: "Production"}).optional(),
|
.string()
|
||||||
active: z.boolean().openapi({example: true}).optional(),
|
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||||
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
.optional(),
|
||||||
|
name: z.string().openapi({ example: "Production" }).optional(),
|
||||||
|
active: z.boolean().openapi({ example: true }).optional(),
|
||||||
|
roles: z
|
||||||
|
.string()
|
||||||
|
.openapi({ example: `["viewer","technician"]` })
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ParamsSchema = z.object({
|
const ParamsSchema = z.object({
|
||||||
server: z
|
server: z
|
||||||
.string()
|
.string()
|
||||||
.min(3)
|
.min(3)
|
||||||
.openapi({
|
.openapi({
|
||||||
param: {
|
param: {
|
||||||
name: "server",
|
name: "server",
|
||||||
in: "path",
|
in: "path",
|
||||||
},
|
},
|
||||||
example: "usbow1",
|
example: "usbow1",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
const UpdateServer = z.object({
|
const UpdateServer = z.object({
|
||||||
devDir: z.string().openapi({example: "C:\\something\\Something"}),
|
devDir: z.string().openapi({ example: "C:\\something\\Something" }),
|
||||||
|
all: z.boolean().optional().openapi({ example: true }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
@@ -48,30 +58,38 @@ app.openapi(
|
|||||||
params: ParamsSchema,
|
params: ParamsSchema,
|
||||||
body: {
|
body: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: UpdateServer},
|
"application/json": { schema: UpdateServer },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: responseSchema},
|
"application/json": { schema: responseSchema },
|
||||||
},
|
},
|
||||||
description: "Response message",
|
description: "Response message",
|
||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: responseSchema},
|
"application/json": { schema: responseSchema },
|
||||||
},
|
},
|
||||||
description: "Response message",
|
description: "Response message",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const {server} = c.req.valid("param");
|
const { server } = c.req.valid("param");
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
|
|
||||||
// fire off the update we wont make this way
|
// fire off the update we wont make this way
|
||||||
|
if (body.all) {
|
||||||
|
const update = await processAllServers(body.devDir);
|
||||||
|
return c.json({
|
||||||
|
success: update?.success ?? false,
|
||||||
|
message: update?.message,
|
||||||
|
data: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const update = await updateServer(body.devDir, server);
|
const update = await updateServer(body.devDir, server);
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ import { serversCheckPoint } from "./utils/serverData.js";
|
|||||||
import getServers from "./route/servers/getServers.js";
|
import getServers from "./route/servers/getServers.js";
|
||||||
import updateServer from "./route/updates/updateServer.js";
|
import updateServer from "./route/updates/updateServer.js";
|
||||||
import { setPerms } from "./utils/testServerPerms.js";
|
import { setPerms } from "./utils/testServerPerms.js";
|
||||||
import serviceControl from './route/servers/serverContorl.js'
|
import serviceControl from "./route/servers/serverContorl.js";
|
||||||
|
import { areSubModulesIn } from "./utils/subModuleCheck.js";
|
||||||
|
|
||||||
// making sure all modules are in properly
|
// making sure all modules are in properly
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
@@ -21,6 +22,7 @@ setTimeout(async () => {
|
|||||||
await areModulesIn();
|
await areModulesIn();
|
||||||
await serversCheckPoint();
|
await serversCheckPoint();
|
||||||
await setPerms();
|
await setPerms();
|
||||||
|
await areSubModulesIn();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
@@ -36,7 +38,7 @@ const routes = [
|
|||||||
// serverData
|
// serverData
|
||||||
getServers,
|
getServers,
|
||||||
updateServer,
|
updateServer,
|
||||||
serviceControl
|
serviceControl,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// app.route("/server", modules);
|
// app.route("/server", modules);
|
||||||
|
|||||||
@@ -20,7 +20,12 @@ export const serversCheckPoint = async () => {
|
|||||||
const serverData = JSON.parse(data);
|
const serverData = JSON.parse(data);
|
||||||
servers = serverData.servers;
|
servers = serverData.servers;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error reading JSON file:", err);
|
createLog(
|
||||||
|
"error",
|
||||||
|
"server",
|
||||||
|
"server",
|
||||||
|
`Error reading JSON file: ${JSON.stringify(err)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the roles
|
// get the roles
|
||||||
|
|||||||
177
server/services/server/utils/subModuleCheck.ts
Normal file
177
server/services/server/utils/subModuleCheck.ts
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
/**
|
||||||
|
* check if the modules are in and if not add them.
|
||||||
|
* this will only run on a server start up
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { db } from "../../../../database/dbclient.js";
|
||||||
|
import { subModules } from "../../../../database/schema/subModules.js";
|
||||||
|
import { createLog } from "../../logger/logger.js";
|
||||||
|
// "view", "technician", "supervisor","manager", "admin", "systemAdmin"
|
||||||
|
const newSubModules = [
|
||||||
|
{
|
||||||
|
name: "Silo Adjustmnet",
|
||||||
|
moduleName: "logistics",
|
||||||
|
description: "Do a silo adjustmnet",
|
||||||
|
link: "/sa",
|
||||||
|
icon: "Cylinder",
|
||||||
|
active: false,
|
||||||
|
roles: ["tester", "systemAdmin"],
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Bulk orders",
|
||||||
|
moduleName: "logistics",
|
||||||
|
description: "",
|
||||||
|
link: "#",
|
||||||
|
icon: "Truck",
|
||||||
|
role: ["systemAdmin"],
|
||||||
|
active: false,
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Forecast",
|
||||||
|
moduleName: "logistics",
|
||||||
|
description: "",
|
||||||
|
link: "#",
|
||||||
|
icon: "Truck",
|
||||||
|
role: ["systemAdmin"],
|
||||||
|
active: false,
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ocme cycle counts",
|
||||||
|
moduleName: "logistics",
|
||||||
|
description: "",
|
||||||
|
link: "#",
|
||||||
|
icon: "Package",
|
||||||
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
active: false,
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Material Helper",
|
||||||
|
moduleName: "logistics",
|
||||||
|
description: "",
|
||||||
|
link: "/materialHelper/consumption",
|
||||||
|
icon: "Package",
|
||||||
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
active: false,
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ocme Cyclecount",
|
||||||
|
moduleName: "logistics",
|
||||||
|
description: "",
|
||||||
|
link: "/cyclecount",
|
||||||
|
icon: "Package",
|
||||||
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
active: false,
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
|
||||||
|
// admin module
|
||||||
|
{
|
||||||
|
name: "Servers",
|
||||||
|
moduleName: "admin",
|
||||||
|
description: "Do a silo adjustmnet",
|
||||||
|
link: "/servers",
|
||||||
|
icon: "Server",
|
||||||
|
roles: ["tester", "systemAdmin"],
|
||||||
|
isActive: true,
|
||||||
|
subSubModule: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Admin",
|
||||||
|
moduleName: "admin",
|
||||||
|
description: "Do a silo adjustmnet",
|
||||||
|
link: "#", // when link is # this will mean its a button
|
||||||
|
icon: "ShieldCheck",
|
||||||
|
active: true,
|
||||||
|
roles: ["tester", "systemAdmin"],
|
||||||
|
subSubModule: [
|
||||||
|
{
|
||||||
|
name: "Settings",
|
||||||
|
link: "/settings",
|
||||||
|
icon: "Settings",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Modules",
|
||||||
|
link: "/modules",
|
||||||
|
icon: "Settings",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Swagger",
|
||||||
|
link: "#",
|
||||||
|
icon: "Webhook",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Logs",
|
||||||
|
link: "#",
|
||||||
|
icon: "Logs",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Users",
|
||||||
|
link: "/users",
|
||||||
|
icon: "Users",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "UCD",
|
||||||
|
link: "https://ucd.alpla.net:8443/",
|
||||||
|
icon: "Atom",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Lst Api",
|
||||||
|
link: "/api/docs",
|
||||||
|
icon: "Webhook",
|
||||||
|
newWindow: false,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
export const areSubModulesIn = async () => {
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < newSubModules.length; i++) {
|
||||||
|
const subModuleUpdate = await db
|
||||||
|
.insert(subModules)
|
||||||
|
.values(newSubModules[i])
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: subModules.name,
|
||||||
|
set: {
|
||||||
|
name: newSubModules[i].name,
|
||||||
|
moduleName: newSubModules[i].moduleName,
|
||||||
|
description: newSubModules[i].description,
|
||||||
|
roles: newSubModules[i].roles,
|
||||||
|
link: newSubModules[i].link,
|
||||||
|
subSubModule: newSubModules[i].subSubModule,
|
||||||
|
},
|
||||||
|
}) // this will only update the ones that are new :D
|
||||||
|
.returning({ name: subModules.name });
|
||||||
|
}
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"lst",
|
||||||
|
"server",
|
||||||
|
"SubModules were just added due to missing them on server startup"
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"lst",
|
||||||
|
"server",
|
||||||
|
"There was an error adding new subModules to the db"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user