agent starting :D

This commit is contained in:
2026-03-01 14:10:19 -06:00
parent c3379919b9
commit 68d13b03d3
34 changed files with 1905 additions and 254 deletions

View File

@@ -15,7 +15,7 @@ const r = Router();
r.get("/", async (_, res: Response) => {
const { data: sName, error: sError } = await tryCatch(
db.select().from(settings),
db.select().from(settings).orderBy(settings.name),
);
if (sError) {

View File

@@ -0,0 +1,334 @@
import { sql } from "drizzle-orm";
import { db } from "../db/db.controller.js";
import { type NewSetting, settings } from "../db/schema/settings.schema.js";
import { createLogger } from "../logger/logger.controller.js";
import { tryCatch } from "../utils/trycatch.utils.js";
const newSettings: NewSetting[] = [
// feature settings
{
name: "opendock_sync",
value: "0",
active: true,
description: "Dock Scheduling system",
moduleName: "opendock",
settingType: "feature",
roles: ["admin"],
seedVersion: 1,
},
{
name: "ocp",
value: "1",
active: true,
description: "One click print",
moduleName: "ocp",
settingType: "feature",
roles: ["admin"],
seedVersion: 1,
},
{
name: "ocme",
value: "0",
active: true,
description: "Dayton Agv system",
moduleName: "ocme",
settingType: "feature",
roles: ["admin"],
seedVersion: 1,
},
{
name: "demandManagement",
value: "1",
active: true,
description: "Fake EDI System",
moduleName: "demandManagement",
settingType: "feature",
roles: ["admin"],
seedVersion: 1,
},
{
name: "qualityRequest",
value: "0",
active: true,
description: "Quality System",
moduleName: "qualityRequest",
settingType: "feature",
roles: ["admin"],
seedVersion: 1,
},
{
name: "tms",
value: "0",
active: true,
description: "Transport system integration",
moduleName: "tms",
settingType: "feature",
roles: ["admin"],
seedVersion: 1,
},
// standard settings
{
name: "prolinkCheck",
value: "1",
active: true,
description:
"Will prolink be considered to check if matches, mainly used in plants that do not fully utilize prolink + ocp",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "bookin",
value: "1",
active: true,
description: "Will we book in the labels after they are printed.",
moduleName: "ocp",
settingType: "standard",
roles: ["admin", "supervisor"],
seedVersion: 2,
},
{
name: "printDelay",
value: "90",
active: true,
description: "The default time between label printing",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "dualPrinting",
value: "0",
active: true,
description: "Are we producing on 2 lines that pack into the 1 packer",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "fifoCheck",
value: "45",
active: true,
description:
"This check is used to do a more near fifo check when pulling pallets for the agv's",
moduleName: "ocme",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "dayCheck",
value: "3",
active: true,
description: "how many days +/- to check for shipments in alplaprod",
moduleName: "ocme",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "maxLotsPerTruck",
value: "3",
active: true,
description:
"What is the maximum amount of lots that can be pulled for a truck this",
moduleName: "ocme",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "monitorAddress",
value: "8",
active: true,
description:
"What address(2) are we monitoring for lot restrictions. multiple addresses can be used but should be separated by a comma ,",
moduleName: "ocme",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "ocmeCycleCount",
value: "0",
active: true,
description:
"Are you enabling the system count page? meaning that we will allow a 'manual cycle count' vs full auto",
moduleName: "ocme",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "inhouseDelivery",
value: "0",
active: true,
description:
"This is for in-house plants that deliver direct to the customer, note if book-in is off this will be ignored ",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "dycoConnect",
value: "0",
active: true,
description: "Connection to the dyco in dayton for the labeling process",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "dycoPrint",
value: "0",
active: true,
description:
"This tells us we want to use the dyco system to print the labels",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "strapperCheck",
value: "0",
active: true,
description:
"Strapper alarm check this is more used in tandem with dycoPrint setting",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "rfid_ocp",
value: "0",
active: true,
description:
"Enable the rfid pallet mgt system this replaces dycoPrint but can be overridden by dycoPrint",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "ocpCycleDelay",
value: "10",
active: true,
description:
"How long is the delay to fire off the printer check status, Defaulting to 10 seconds",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "pNgAddress",
value: "139",
active: true,
description:
"This is the P&G address that is used when uploading the new forecast from P&G",
moduleName: "demandManagement",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "zechetti_1",
value: "0",
active: true,
description:
"Active the Zechetti 1 process, to print from and no longer utilize the pc",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "zechetti_2",
value: "0",
active: true,
description:
"Active the Zechetti 2 process, to print from and no longer utilize the pc",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "checkColor",
value: "0",
active: true,
description:
"During the material check are we going to check the color has enough provided to create the next pallet",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "checkPKG",
value: "0",
active: true,
description:
"During the material check are we going to check the packaging has enough provided to create the next pallet",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
{
name: "lotPrintDelay",
value: "0",
active: true,
description:
"Override ride the printer printer delay setting, by default if this is on all printers are controlled by this.",
moduleName: "ocp",
settingType: "standard",
roles: ["admin"],
seedVersion: 1,
},
];
export const baseSettingValidationCheck = async () => {
const log = createLogger({ module: "system", subModule: "settings" });
const { data, error } = await tryCatch(
db
.insert(settings)
.values(newSettings)
.onConflictDoUpdate({
target: settings.name,
set: {
roles: sql`excluded.roles`,
description: sql`excluded.description`,
moduleName: sql`excluded."moduleName"`,
settingType: sql`excluded."settingType"`,
seedVersion: sql`excluded.seed_version`,
upd_user: "LST_System",
upd_date: sql`now()`,
},
where: sql`
settings.seed_version IS NULL
OR settings.seed_version < excluded.seed_version
`,
})
.returning(),
);
if (error) {
log.error(
{ error: error },
"There was an error when adding or updating the settings.",
);
}
if (data) {
log.info({}, "All Settings were added/updated");
}
};

View File

@@ -0,0 +1,16 @@
/**
* When a feature setting gets updated we will handle it here.
* we will stop jobs, stop cycles
*/
import type { Setting } from "../db/schema/settings.schema.js";
import { 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);
}
};

View File

@@ -5,9 +5,8 @@ import { settings } from "../db/schema/settings.schema.js";
import { apiReturn } from "../utils/returnHelper.utils.js";
import { tryCatch } from "../utils/trycatch.utils.js";
import { featureControl } from "./settingsFeatures.controller.js";
// export const updateSetting = async (setting: Setting) => {
// // TODO: when the setting is a feature setting we will need to have it run each kill switch on the crons well just stop them and during a reset it just wont start them
// // TODO: when the setting is a system we will need to force an app restart
// // TODO: when the setting is standard we don't do anything.
// };
@@ -38,17 +37,17 @@ r.patch("/:name", async (req: Request, res: Response) => {
});
}
// if (sName?.length === 0) {
// return apiReturn(res, {
// success: false,
// level: "error",
// module: "system",
// subModule: "settings",
// message: `The setting "${name}" dose not appear to be a valid setting please check the name and try again. `,
// data: [],
// status: 400,
// });
// }
if (sName?.length === 0) {
return apiReturn(res, {
success: false,
level: "error",
module: "system",
subModule: "settings",
message: `The setting "${name}" dose not appear to be a valid setting please check the name and try again. `,
data: [],
status: 400,
});
}
// manage the actual setting. we will still do an upsert just in case we strangely get past everything
@@ -79,14 +78,32 @@ r.patch("/:name", async (req: Request, res: Response) => {
updates.upd_user = req.user?.username || "lst_user";
updates.upd_date = sql`NOW()`;
const updatedSetting = await db
.update(settings)
.set(updates)
.where(eq(settings.name, name ?? ""))
.returning();
// the switch statment will only run when the setting actually updates
switch (updatedSetting[0]?.settingType) {
case "feature":
await featureControl(updatedSetting[0]);
break;
case "system":
// TODO: add the system control logic in to restart the app if not in dev mode
break;
default:
break;
}
return apiReturn(res, {
success: true,
level: "info",
module: "system",
subModule: "settings",
message: `Setting "${name}" Was just updated. `,
data: [updates],
status: 400,
data: updatedSetting,
status: 200,
});
});