feat(rfid): new check to remove tags that have been at a line longer than 6 hours
This commit is contained in:
@@ -7,6 +7,7 @@ import updateReader from "./route/updateReader.js";
|
|||||||
import manualTrigger from "./route/manualTagRead.js";
|
import manualTrigger from "./route/manualTagRead.js";
|
||||||
import getReaders from "./route/getReaders.js";
|
import getReaders from "./route/getReaders.js";
|
||||||
import resetRatio from "./route/resetRatio.js";
|
import resetRatio from "./route/resetRatio.js";
|
||||||
|
import { monitorRfidTags } from "./utils/monitorTags.js";
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
@@ -24,4 +25,9 @@ const appRoutes = routes.forEach((route) => {
|
|||||||
app.route("/rfid", route);
|
app.route("/rfid", route);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// monitor every 5 min tags older than 6 hours to remove the line they were so we reduce the risk of them being labeled with the wrong info
|
||||||
|
setInterval(() => {
|
||||||
|
monitorRfidTags();
|
||||||
|
}, 5 * 1000 * 60);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
22
server/services/rfid/utils/monitorTags.ts
Normal file
22
server/services/rfid/utils/monitorTags.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { and, lt, ne, sql } from "drizzle-orm";
|
||||||
|
import { db } from "../../../../database/dbclient.js";
|
||||||
|
import { rfidTags } from "../../../../database/schema/rfidTags.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will monitor tags that are older than 6hours and are still linked to a line.
|
||||||
|
* it will then remove the line from the last area in as we will asume it dose not exist.
|
||||||
|
*/
|
||||||
|
export const monitorRfidTags = async () => {
|
||||||
|
const { data, error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.update(rfidTags)
|
||||||
|
.set({ lastareaIn: "miss scanned" })
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
ne(rfidTags.lastareaIn, "wrapper1"), // not equal to 'wrapper1'
|
||||||
|
lt(rfidTags.lastRead, sql`NOW() - INTERVAL '6 hours'`) // older than 6 hours)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -198,6 +198,13 @@ const newSettings = [
|
|||||||
serviceBelowsTo: "system",
|
serviceBelowsTo: "system",
|
||||||
roleToChange: "admin",
|
roleToChange: "admin",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "rifd",
|
||||||
|
value: `0`,
|
||||||
|
description: "This is for dayton to be runnning rfid pallet tracking.",
|
||||||
|
serviceBelowsTo: "logistics",
|
||||||
|
roleToChange: "admin",
|
||||||
|
},
|
||||||
|
|
||||||
// ocp
|
// ocp
|
||||||
{
|
{
|
||||||
@@ -244,6 +251,13 @@ const newSettings = [
|
|||||||
serviceBelowsTo: "logistics",
|
serviceBelowsTo: "logistics",
|
||||||
roleToChange: "admin",
|
roleToChange: "admin",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "zechetti",
|
||||||
|
value: `0`,
|
||||||
|
description: "Are we going to be running the Zechetti plcs",
|
||||||
|
serviceBelowsTo: "logistics",
|
||||||
|
roleToChange: "admin",
|
||||||
|
},
|
||||||
// temp settings can be deleted at a later date once that code is removed
|
// temp settings can be deleted at a later date once that code is removed
|
||||||
{
|
{
|
||||||
name: "checkColor",
|
name: "checkColor",
|
||||||
|
|||||||
Reference in New Issue
Block a user