feat(ocp): printer cycling backend and frontend done :)
This commit is contained in:
@@ -4,13 +4,23 @@ import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { getPrinters } from "./getPrinters.js";
|
||||
import { printerStatus } from "./printerStatus.js";
|
||||
import { autoLabelingStats, printerStatus } from "./printerStatus.js";
|
||||
|
||||
let isPrinterCycling = false;
|
||||
let actualPrinterCycle: any;
|
||||
|
||||
export const printerCycle = async () => {
|
||||
/**
|
||||
* We will cycle through the printers to check there states.
|
||||
*/
|
||||
|
||||
if (isPrinterCycling)
|
||||
return {
|
||||
success: false,
|
||||
message: "Printers are already being cycled.",
|
||||
};
|
||||
|
||||
createLog("info", "ocp", "ocp", "Printer cycle has started.");
|
||||
// get the printers
|
||||
const { data: s, error: se } = await tryCatch(
|
||||
db.select().from(settings).where(eq(settings.name, "ocpCycleDelay"))
|
||||
@@ -29,9 +39,9 @@ export const printerCycle = async () => {
|
||||
}
|
||||
|
||||
const ocpDelay: any = s;
|
||||
|
||||
isPrinterCycling = true;
|
||||
// start the actual printer cycle
|
||||
const actualPrinterCycle = setInterval(async () => {
|
||||
actualPrinterCycle = setInterval(async () => {
|
||||
const { data, error } = await tryCatch(getPrinters());
|
||||
|
||||
if (error) {
|
||||
@@ -51,10 +61,8 @@ export const printerCycle = async () => {
|
||||
// only keep the assigned ones
|
||||
printers = printers.filter((p: any) => p.assigned === true);
|
||||
|
||||
// for autolabelers like dayton and MCD we want to ignore them from the loop as well.
|
||||
printers = printers.filter(
|
||||
(p: any) => p.name != "Autolabeler" && !p.remark.includes("ignore")
|
||||
);
|
||||
// for printers we want to ignore there must be a remark stateing to ignore.
|
||||
printers = printers.filter((p: any) => !p.remark.includes("ignore"));
|
||||
|
||||
printers.forEach(async (p: any) => {
|
||||
/**
|
||||
@@ -75,7 +83,31 @@ export const printerCycle = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.name === "Autolabeler") {
|
||||
await autoLabelingStats(p);
|
||||
return;
|
||||
}
|
||||
|
||||
// for all other printers
|
||||
await printerStatus(p);
|
||||
});
|
||||
}, parseInt(ocpDelay[0]?.value) * 1000);
|
||||
|
||||
return { success: true, message: "Printer cycle has been started." };
|
||||
};
|
||||
|
||||
export const stopPrinterCycle = async () => {
|
||||
/**
|
||||
* We will stop the print cylce this is more an emergancy thing.
|
||||
*/
|
||||
if (actualPrinterCycle && !actualPrinterCycle._destroyed) {
|
||||
createLog("info", "ocp", "ocp", "Printer cycle is being stopped.");
|
||||
clearInterval(actualPrinterCycle);
|
||||
isPrinterCycling = false;
|
||||
return { success: true, message: "Printer cycle has been stopped." };
|
||||
} else {
|
||||
createLog("info", "ocp", "ocp", "Printer cycle is already stopped.");
|
||||
isPrinterCycling = false;
|
||||
return { success: true, message: "Printer cycle is already Stopped." };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user