refactor(ocp): more work on perfecting dyco and labeling
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
import { eq } from "drizzle-orm";
|
|
||||||
import { db } from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import { printers } from "../../../../../database/schema/printers.js";
|
|
||||||
import { settings } from "../../../../../database/schema/settings.js";
|
import { settings } from "../../../../../database/schema/settings.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { createLog } from "../../../logger/logger.js";
|
import { createLog } from "../../../logger/logger.js";
|
||||||
|
|||||||
@@ -80,11 +80,12 @@ export const labelerTagRead = async (tagData: any) => {
|
|||||||
} else {
|
} else {
|
||||||
currentPalletCheck = 0;
|
currentPalletCheck = 0;
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"warn",
|
||||||
"dyco",
|
"dyco",
|
||||||
"ocp",
|
"ocp",
|
||||||
`You have reached 20 pallets since the last check please validate the labeler is still in sync.`
|
`You have reached 20 pallets since the last check please validate the labeler is still in sync.`
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,27 @@ import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
|
|||||||
import { createLog } from "../../../../../logger/logger.js";
|
import { createLog } from "../../../../../logger/logger.js";
|
||||||
|
|
||||||
// strapper related issues
|
// strapper related issues
|
||||||
export let strapperActive = true;
|
export let strapperActive = false;
|
||||||
export let stapperFaulted = false;
|
export let stapperFaulted = false;
|
||||||
export let strapperFaultCount = 3; // move to db so we can control it outside the app
|
export let strapperFaultCount = 3; // move to db so we can control it outside the app
|
||||||
let alreadyAlerted = false;
|
|
||||||
|
|
||||||
export const strapperFaults = async (tagData: any) => {
|
export const strapperFaults = async (tagData: any) => {
|
||||||
const { data, error } = await tryCatch(db.select().from(settings));
|
const { data, error } = await tryCatch(db.select().from(settings));
|
||||||
|
|
||||||
|
// failed to get settings
|
||||||
if (error) {
|
if (error) {
|
||||||
return { success: false, message: "Failed to get settings." };
|
return { success: false, message: "Failed to get settings." };
|
||||||
}
|
}
|
||||||
|
|
||||||
const strapperCheckSetting = data.filter((n) => n.name === "strapperCheck");
|
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") {
|
if (strapperCheckSetting[0]?.value === "1") {
|
||||||
|
// faulted and still has a check or 2 to go
|
||||||
if (stapperFaulted && strapperFaultCount > 0) {
|
if (stapperFaulted && strapperFaultCount > 0) {
|
||||||
createLog(
|
createLog(
|
||||||
"warn",
|
"warn",
|
||||||
@@ -26,13 +32,13 @@ export const strapperFaults = async (tagData: any) => {
|
|||||||
"ocp",
|
"ocp",
|
||||||
`There was a strapper error, remaining pallets to check ${strapperFaultCount}.`
|
`There was a strapper error, remaining pallets to check ${strapperFaultCount}.`
|
||||||
);
|
);
|
||||||
alreadyAlerted = true;
|
|
||||||
strapperFaultCount = strapperFaultCount - 1;
|
strapperFaultCount = strapperFaultCount - 1;
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: true,
|
||||||
message: `There was a strapper error, remaining pallets to check ${strapperFaultCount}.`,
|
message: `There was a strapper error, remaining pallets to check ${strapperFaultCount}.`,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// no more checks needed clearing everything
|
||||||
createLog(
|
createLog(
|
||||||
"debug",
|
"debug",
|
||||||
"dyco",
|
"dyco",
|
||||||
@@ -45,14 +51,13 @@ export const strapperFaults = async (tagData: any) => {
|
|||||||
strapperFaultCount = 3; // move to db as well
|
strapperFaultCount = 3; // move to db as well
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: false,
|
||||||
message: `Strapper check is active but not faulted, remaining pallets to check ${strapperFaultCount}.`,
|
message: `Strapper check is active but not faulted, remaining pallets to check ${strapperFaultCount}.`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strapperActive) {
|
// strapper was triggered turning on the counter.
|
||||||
// monitor strapper
|
|
||||||
//console.log(`Strapper fault is ${strapperError.value}`);
|
//console.log(`Strapper fault is ${strapperError.value}`);
|
||||||
if (tagData.value && strapperFaultCount > 0) {
|
if (tagData.value && strapperFaultCount > 0) {
|
||||||
// strapper faulted we want to start the trigger to force the check
|
// strapper faulted we want to start the trigger to force the check
|
||||||
@@ -61,14 +66,21 @@ export const strapperFaults = async (tagData: any) => {
|
|||||||
"error",
|
"error",
|
||||||
"dyco",
|
"dyco",
|
||||||
"ocp",
|
"ocp",
|
||||||
`Strapper errored triggering manual checks will be required for the next ${strapperFaultCount}`
|
`Strapper errored triggering, manual checks will be required for the next ${strapperFaultCount}`
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
stapperFaulted = true;
|
stapperFaulted = true;
|
||||||
alreadyAlerted = true;
|
|
||||||
// change move fault count to db....
|
// change move fault count to db....
|
||||||
strapperFaultCount = 3;
|
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. :)`,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 { createLog } from "../../../../logger/logger.js";
|
||||||
import { query } from "../../../../sqlServer/prodSqlServer.js";
|
import { query } from "../../../../sqlServer/prodSqlServer.js";
|
||||||
import { machineCheck } from "../../../../sqlServer/querys/ocp/machineId.js";
|
import { machineCheck } from "../../../../sqlServer/querys/ocp/machineId.js";
|
||||||
|
|||||||
Reference in New Issue
Block a user