refactor(ocp): more work on perfecting dyco and labeling

This commit is contained in:
2025-04-01 16:22:21 -05:00
parent bc2336e46d
commit 8bdbc4995c
5 changed files with 35 additions and 27 deletions

View File

@@ -1,6 +1,4 @@
import { eq } from "drizzle-orm";
import { db } from "../../../../../database/dbclient.js";
import { printers } from "../../../../../database/schema/printers.js";
import { settings } from "../../../../../database/schema/settings.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../logger/logger.js";

View File

@@ -80,11 +80,12 @@ export const labelerTagRead = async (tagData: any) => {
} else {
currentPalletCheck = 0;
createLog(
"error",
"warn",
"dyco",
"ocp",
`You have reached 20 pallets since the last check please validate the labeler is still in sync.`
);
return;
}
}

View File

@@ -4,21 +4,27 @@ import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../../../logger/logger.js";
// strapper related issues
export let strapperActive = true;
export let strapperActive = false;
export let stapperFaulted = false;
export let strapperFaultCount = 3; // move to db so we can control it outside the app
let alreadyAlerted = false;
export const strapperFaults = async (tagData: any) => {
const { data, error } = await tryCatch(db.select().from(settings));
// failed to get settings
if (error) {
return { success: false, message: "Failed to get settings." };
}
const strapperCheckSetting = data.filter((n) => n.name === "strapperCheck");
// strapper error is off
if (strapperCheckSetting[0]?.value === "0") {
return;
}
// strapper error is on
if (strapperCheckSetting[0]?.value === "1") {
// faulted and still has a check or 2 to go
if (stapperFaulted && strapperFaultCount > 0) {
createLog(
"warn",
@@ -26,13 +32,13 @@ export const strapperFaults = async (tagData: any) => {
"ocp",
`There was a strapper error, remaining pallets to check ${strapperFaultCount}.`
);
alreadyAlerted = true;
strapperFaultCount = strapperFaultCount - 1;
return {
success: false,
success: true,
message: `There was a strapper error, remaining pallets to check ${strapperFaultCount}.`,
};
} else {
// no more checks needed clearing everything
createLog(
"debug",
"dyco",
@@ -45,30 +51,36 @@ export const strapperFaults = async (tagData: any) => {
strapperFaultCount = 3; // move to db as well
return {
success: true,
success: false,
message: `Strapper check is active but not faulted, remaining pallets to check ${strapperFaultCount}.`,
};
}
}
if (strapperActive) {
// monitor strapper
//console.log(`Strapper fault is ${strapperError.value}`);
if (tagData.value && strapperFaultCount > 0) {
// strapper faulted we want to start the trigger to force the check
if (!stapperFaulted) {
createLog(
"error",
"dyco",
"ocp",
`Strapper errored triggering manual checks will be required for the next ${strapperFaultCount}`
);
}
// strapper was triggered turning on the counter.
//console.log(`Strapper fault is ${strapperError.value}`);
if (tagData.value && strapperFaultCount > 0) {
// strapper faulted we want to start the trigger to force the check
if (!stapperFaulted) {
createLog(
"error",
"dyco",
"ocp",
`Strapper errored triggering, manual checks will be required for the next ${strapperFaultCount}`
);
stapperFaulted = true;
alreadyAlerted = true;
// change move fault count to db....
strapperFaultCount = 3;
return {
success: true,
message: `Strapper errored triggering, manual checks will be required for the next ${strapperFaultCount}`,
};
}
}
return {
success: false,
message: `Some how we made it here and just going to say we are good. :)`,
};
};

View File

@@ -1,6 +1,3 @@
import { db } from "../../../../../../database/dbclient.js";
import { settings } from "../../../../../../database/schema/settings.js";
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
import { createLog } from "../../../../logger/logger.js";
import { query } from "../../../../sqlServer/prodSqlServer.js";
import { machineCheck } from "../../../../sqlServer/querys/ocp/machineId.js";