Files
lstV2/server/services/ocp/utils/checkAssignments.ts

88 lines
2.9 KiB
TypeScript

import { delay } from "../../../globalUtils/delay.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getLots } from "../controller/lots/lots.js";
import { getPrinters } from "../controller/printers/getPrinters.js";
export const assignedPrinters = async () => {
const { data: l, error: lotError } = await tryCatch(getLots());
if (lotError) {
return {
success: false,
message: "Error getting lots",
data: lotError,
};
}
const { data: print, error: printerError } = await tryCatch(getPrinters());
if (printerError) {
return {
success: false,
message: "Error getting lots",
data: printerError,
};
}
const printers: any = print;
const lots: any = l;
for (let i = 0; i < printers.data.length; i++) {
// is the printer assinged in alplalabel online?
const assigned = lots.data.filter(
(p: any) => p.printerID === printers[i].humanReadableId
);
let assignedPrinter = false;
// if true update the assigned field to true
if (assigned.length >= 1) {
assignedPrinter = true;
}
// if the last time printed is greater than 5 min change the status to 10
// const lastTime = new Date(printers[i].lastTimePrinted);
// let status = printers[i].status;
// let statusText = printers[i].statusText;
// // states we consider idle
// const printerStateCheck = [1, 2, 3, 4, 5, 6, 10];
// if (
// differenceInMinutes(currentTime, lastTime) >= 60 &&
// printerStateCheck.includes(printers[i].status) &&
// printers[i].assigned
// ) {
// createLog(
// "printerState",
// "info",
// `${printers[i].name} has been idle for more than 60 min, doing a heartbeat check`
// );
// status = 11;
// statusText = "idle";
// // printerState({printerCheck: printers[i]});
// } else if (differenceInMinutes(currentTime, lastTime) > 5 && printers[i].status === 7) {
// createLog(
// "printerState",
// "info",
// `${printers[i].name} has been errored for more 5 min changing to idle until, until it gets checked at the hour heartbeat.`
// );
// status = 10;
// statusText = "idle";
// }
// const updatePrinter = await prisma.printers.update({
// where: {
// humanReadableId: printers[i].humanReadableId,
// },
// data: {
// assigned: assignedPrinter,
// // status,
// // statusText,
// upd_date: new Date(Date.now()).toISOString(),
// },
// });
//delaying 250ms
await delay(250);
}
};