Compare commits
4 Commits
712a6eebdf
...
6833dfc992
| Author | SHA1 | Date | |
|---|---|---|---|
| 6833dfc992 | |||
| ac27a286c0 | |||
| a3dba6cc9d | |||
| 320dd47aea |
15
LogisticsSupportTool_API_DOCS/LstV2/ocp/Logs.bru
Normal file
15
LogisticsSupportTool_API_DOCS/LstV2/ocp/Logs.bru
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
meta {
|
||||||
|
name: Logs
|
||||||
|
type: http
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url:
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
vars {
|
vars {
|
||||||
url: https://usflo1prod.alpla.net
|
url: https://usday1prod.alpla.net
|
||||||
session_cookie:
|
session_cookie:
|
||||||
urlv2: http://usbow1vms006:3000
|
urlv2: http://usbow1vms006:3000
|
||||||
jwtV2:
|
jwtV2:
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { returnFunc } from "../utils/return.js";
|
|
||||||
import { connected, pool } from "./prodSqlConnect.js";
|
|
||||||
import { validateEnv } from "../utils/envValidator.js";
|
import { validateEnv } from "../utils/envValidator.js";
|
||||||
|
import { returnFunc } from "../utils/return.js";
|
||||||
|
import {
|
||||||
|
closePool,
|
||||||
|
connected,
|
||||||
|
pool,
|
||||||
|
reconnecting,
|
||||||
|
reconnectToSql,
|
||||||
|
} from "./prodSqlConnect.js";
|
||||||
|
|
||||||
const env = validateEnv(process.env);
|
const env = validateEnv(process.env);
|
||||||
/**
|
/**
|
||||||
@@ -12,6 +18,19 @@ const env = validateEnv(process.env);
|
|||||||
*/
|
*/
|
||||||
export async function prodQuery(queryToRun: string, name: string) {
|
export async function prodQuery(queryToRun: string, name: string) {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
reconnectToSql();
|
||||||
|
|
||||||
|
if (reconnecting) {
|
||||||
|
return returnFunc({
|
||||||
|
success: false,
|
||||||
|
module: "prodSql",
|
||||||
|
subModule: "query",
|
||||||
|
level: "error",
|
||||||
|
message: `The sql ${env.PROD_PLANT_TOKEN} is trying to reconnect already`,
|
||||||
|
notify: false,
|
||||||
|
data: [],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
return returnFunc({
|
return returnFunc({
|
||||||
success: false,
|
success: false,
|
||||||
module: "prodSql",
|
module: "prodSql",
|
||||||
@@ -22,6 +41,8 @@ export async function prodQuery(queryToRun: string, name: string) {
|
|||||||
data: [],
|
data: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const query = queryToRun.replaceAll("test1", env.PROD_PLANT_TOKEN);
|
const query = queryToRun.replaceAll("test1", env.PROD_PLANT_TOKEN);
|
||||||
try {
|
try {
|
||||||
const result = await pool.request().query(query);
|
const result = await pool.request().query(query);
|
||||||
@@ -33,6 +54,7 @@ export async function prodQuery(queryToRun: string, name: string) {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
if (error.code === "ETIMEOUT") {
|
if (error.code === "ETIMEOUT") {
|
||||||
|
closePool();
|
||||||
return returnFunc({
|
return returnFunc({
|
||||||
success: false,
|
success: false,
|
||||||
module: "prodSql",
|
module: "prodSql",
|
||||||
@@ -45,6 +67,7 @@ export async function prodQuery(queryToRun: string, name: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error.code === "EREQUEST") {
|
if (error.code === "EREQUEST") {
|
||||||
|
closePool();
|
||||||
return returnFunc({
|
return returnFunc({
|
||||||
success: false,
|
success: false,
|
||||||
module: "prodSql",
|
module: "prodSql",
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import sql from "mssql";
|
import sql from "mssql";
|
||||||
import { checkHostnamePort } from "../utils/checkHostNamePort.js";
|
|
||||||
import { sqlConfig } from "./prodSqlConfig.js";
|
|
||||||
import { createLogger } from "../logger/logger.js";
|
import { createLogger } from "../logger/logger.js";
|
||||||
import { returnFunc } from "../utils/return.js";
|
import { checkHostnamePort } from "../utils/checkHostNamePort.js";
|
||||||
import { validateEnv } from "../utils/envValidator.js";
|
import { validateEnv } from "../utils/envValidator.js";
|
||||||
|
import { returnFunc } from "../utils/return.js";
|
||||||
|
import { sqlConfig } from "./prodSqlConfig.js";
|
||||||
|
|
||||||
const env = validateEnv(process.env);
|
const env = validateEnv(process.env);
|
||||||
|
|
||||||
export let pool: any;
|
export let pool: any;
|
||||||
export let connected: boolean = false;
|
export let connected: boolean = false;
|
||||||
let reconnecting = false;
|
export let reconnecting = false;
|
||||||
|
|
||||||
export const initializeProdPool = async () => {
|
export const initializeProdPool = async () => {
|
||||||
const log = createLogger({ module: "prodSql" });
|
const log = createLogger({ module: "prodSql" });
|
||||||
@@ -41,21 +41,19 @@ export const initializeProdPool = async () => {
|
|||||||
pool = await sql.connect(sqlConfig);
|
pool = await sql.connect(sqlConfig);
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`Connected to ${sqlConfig?.server}, using DB: ${sqlConfig?.database}`
|
`Connected to ${sqlConfig?.server}, using DB: ${sqlConfig?.database}`,
|
||||||
);
|
);
|
||||||
connected = true;
|
connected = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.fatal(
|
log.fatal(
|
||||||
`${JSON.stringify(
|
`${JSON.stringify(error)}, "There was an error connecting to the pool."`,
|
||||||
error
|
|
||||||
)}, "There was an error connecting to the pool."`
|
|
||||||
);
|
);
|
||||||
reconnectToSql();
|
reconnectToSql();
|
||||||
// throw new Error("There was an error closing the sql connection");
|
// throw new Error("There was an error closing the sql connection");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const reconnectToSql = async () => {
|
export const reconnectToSql = async () => {
|
||||||
const log = createLogger({ module: "prodSql" });
|
const log = createLogger({ module: "prodSql" });
|
||||||
if (reconnecting) return;
|
if (reconnecting) return;
|
||||||
reconnecting = true;
|
reconnecting = true;
|
||||||
@@ -67,9 +65,7 @@ const reconnectToSql = async () => {
|
|||||||
while (!connected && attempts < maxAttempts) {
|
while (!connected && attempts < maxAttempts) {
|
||||||
attempts++;
|
attempts++;
|
||||||
log.info(
|
log.info(
|
||||||
`Reconnect attempt ${attempts}/${maxAttempts} in ${
|
`Reconnect attempt ${attempts}/${maxAttempts} in ${delay / 1000}s...`,
|
||||||
delay / 1000
|
|
||||||
}s...`
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await new Promise((res) => setTimeout(res, delay));
|
await new Promise((res) => setTimeout(res, delay));
|
||||||
@@ -85,15 +81,15 @@ const reconnectToSql = async () => {
|
|||||||
pool = sql.connect(sqlConfig);
|
pool = sql.connect(sqlConfig);
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`Connected to ${sqlConfig?.server}, and looking at ${sqlConfig?.database}`
|
`Connected to ${sqlConfig?.server}, and looking at ${sqlConfig?.database}`,
|
||||||
);
|
);
|
||||||
reconnecting = false;
|
reconnecting = false;
|
||||||
connected = true;
|
connected = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.fatal(
|
log.fatal(
|
||||||
`${JSON.stringify(
|
`${JSON.stringify(
|
||||||
error
|
error,
|
||||||
)}, "There was an error connecting to the pool."`
|
)}, "There was an error connecting to the pool."`,
|
||||||
);
|
);
|
||||||
delay = Math.min(delay * 2, 30000); // exponential backoff up to 30s
|
delay = Math.min(delay * 2, 30000); // exponential backoff up to 30s
|
||||||
// throw new Error("There was an error closing the sql connection");
|
// throw new Error("There was an error closing the sql connection");
|
||||||
@@ -103,10 +99,10 @@ const reconnectToSql = async () => {
|
|||||||
if (!connected) {
|
if (!connected) {
|
||||||
log.fatal(
|
log.fatal(
|
||||||
{ notify: true },
|
{ notify: true },
|
||||||
"Max reconnect attempts reached on the prodSql server. Stopping retries."
|
"Max reconnect attempts reached on the prodSql server. Stopping retries.",
|
||||||
);
|
);
|
||||||
reconnecting = false;
|
reconnecting = false;
|
||||||
// optional: exit process or alert someone here
|
// exit process or alert someone here
|
||||||
// process.exit(1);
|
// process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -126,11 +122,13 @@ export const closePool = async () => {
|
|||||||
message: "The sql server connection has been closed",
|
message: "The sql server connection has been closed",
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.fatal(
|
connected = false;
|
||||||
{ notify: true },
|
log.info(
|
||||||
|
//{ notify: true },
|
||||||
|
{ error: error },
|
||||||
`${JSON.stringify(
|
`${JSON.stringify(
|
||||||
error
|
error,
|
||||||
)}, "There was an error closing the sql connection"`
|
)}, "There was an error closing the sql connection"`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,10 +10,14 @@ export default function HelperPage() {
|
|||||||
<Bookin />
|
<Bookin />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="m-1">
|
||||||
|
{url === "localhost" && (
|
||||||
<div className="m-1">
|
<div className="m-1">
|
||||||
<RemoveAsNonReusable />
|
<RemoveAsNonReusable />
|
||||||
|
<Relocate />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="m-1">{url === "localhost" && <Relocate />}</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { createLog } from "../services/logger/logger.js";
|
||||||
import { prodEndpointCreation } from "./createUrl.js";
|
import { prodEndpointCreation } from "./createUrl.js";
|
||||||
import { tryCatch } from "./tryCatch.js";
|
import { tryCatch } from "./tryCatch.js";
|
||||||
import { createLog } from "../services/logger/logger.js";
|
|
||||||
|
|
||||||
type bodyData = any;
|
type bodyData = any;
|
||||||
|
|
||||||
@@ -9,11 +9,13 @@ type Data = {
|
|||||||
endpoint: string;
|
endpoint: string;
|
||||||
data: bodyData[];
|
data: bodyData[];
|
||||||
};
|
};
|
||||||
export const runProdApi = async (data: Data) => {
|
|
||||||
/**
|
/**
|
||||||
* Detachs a silo
|
*
|
||||||
|
* @param data
|
||||||
|
* @param timeoutDelay
|
||||||
|
* @returns
|
||||||
*/
|
*/
|
||||||
|
export const runProdApi = async (data: Data) => {
|
||||||
let url = await prodEndpointCreation(data.endpoint);
|
let url = await prodEndpointCreation(data.endpoint);
|
||||||
|
|
||||||
const { data: d, error } = await tryCatch(
|
const { data: d, error } = await tryCatch(
|
||||||
@@ -22,7 +24,7 @@ export const runProdApi = async (data: Data) => {
|
|||||||
"X-API-Key": process.env.TEC_API_KEY || "",
|
"X-API-Key": process.env.TEC_API_KEY || "",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let e = error as any;
|
let e = error as any;
|
||||||
@@ -33,11 +35,11 @@ export const runProdApi = async (data: Data) => {
|
|||||||
"error",
|
"error",
|
||||||
"lst",
|
"lst",
|
||||||
"logistics",
|
"logistics",
|
||||||
`Not autorized: ${JSON.stringify(e.response?.data)}`
|
`Not authorized: ${JSON.stringify(e.response?.data)}`,
|
||||||
);
|
);
|
||||||
const data = {
|
const data = {
|
||||||
success: false,
|
success: false,
|
||||||
message: `Not autorized: ${JSON.stringify(e.response?.data)}`,
|
message: `Not authorized: ${JSON.stringify(e.response?.data)}`,
|
||||||
data: {
|
data: {
|
||||||
status: e.response?.status,
|
status: e.response?.status,
|
||||||
statusText: e.response?.statusText,
|
statusText: e.response?.statusText,
|
||||||
@@ -51,13 +53,13 @@ export const runProdApi = async (data: Data) => {
|
|||||||
"lst",
|
"lst",
|
||||||
"logistics",
|
"logistics",
|
||||||
`There was an error processing the endpoint: ${JSON.stringify(
|
`There was an error processing the endpoint: ${JSON.stringify(
|
||||||
e.response?.data
|
e.response?.data,
|
||||||
)}`
|
)}`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: `There was an error processing the endpoint: ${JSON.stringify(
|
message: `There was an error processing the endpoint: ${JSON.stringify(
|
||||||
e.response?.data
|
e.response?.data,
|
||||||
)}`,
|
)}`,
|
||||||
data: {
|
data: {
|
||||||
status: e.response?.status,
|
status: e.response?.status,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { eq } from "drizzle-orm";
|
|||||||
import { success } from "zod/v4";
|
import { success } from "zod/v4";
|
||||||
import { db } from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import { printerData } from "../../../../../database/schema/printers.js";
|
import { printerData } from "../../../../../database/schema/printers.js";
|
||||||
|
import { delay } from "../../../../globalUtils/delay.js";
|
||||||
import { runProdApi } from "../../../../globalUtils/runProdApi.js";
|
import { runProdApi } from "../../../../globalUtils/runProdApi.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";
|
||||||
@@ -158,7 +159,7 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeoutTrans: number = data.type === "lot" ? 30 : 10;
|
let timeoutTrans: number = data.type === "lot" ? 5 : 5;
|
||||||
// get the barcode, and layoutID from the running number
|
// get the barcode, and layoutID from the running number
|
||||||
const { data: label, error: labelError } = (await tryCatch(
|
const { data: label, error: labelError } = (await tryCatch(
|
||||||
query(
|
query(
|
||||||
@@ -278,13 +279,10 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//console.log(matReturnData);
|
//console.log(matReturnData);
|
||||||
const { data: matReturn, error: matReturError } = (await tryCatch(
|
|
||||||
runProdApi({
|
// set a delay for when we try to return the label
|
||||||
endpoint:
|
|
||||||
"/public/v1.0/IssueMaterial/ReturnPartiallyConsumedManualMaterial",
|
const matReturn = await returnMaterial(matReturnData);
|
||||||
data: [matReturnData],
|
|
||||||
}),
|
|
||||||
)) as any;
|
|
||||||
|
|
||||||
if (!matReturn.success) {
|
if (!matReturn.success) {
|
||||||
createLog(
|
createLog(
|
||||||
@@ -305,12 +303,12 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
|||||||
barcode: label?.data[0].Barcode,
|
barcode: label?.data[0].Barcode,
|
||||||
};
|
};
|
||||||
|
|
||||||
const delay =
|
const delayTimer =
|
||||||
data.type === "lot"
|
data.type === "lot"
|
||||||
? timeoutTrans * 1000
|
? timeoutTrans * 1000
|
||||||
: target.getTime() - now.getTime();
|
: target.getTime() - now.getTime();
|
||||||
|
|
||||||
const transfer = await transferMaterial(delay, data, consumeLot, newQty);
|
const transfer = await transferMaterial(delayTimer, data, consumeLot, newQty);
|
||||||
|
|
||||||
if (!transfer.success) {
|
if (!transfer.success) {
|
||||||
return {
|
return {
|
||||||
@@ -340,6 +338,22 @@ export const lotMaterialTransfer = async (data: NewLotData) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const returnMaterial = async (matReturnData: any) => {
|
||||||
|
console.log("Getting ready to Returning Materials");
|
||||||
|
await delay(5 * 1000);
|
||||||
|
console.log("doing the return");
|
||||||
|
const { data: matReturn, error: matReturError } = (await tryCatch(
|
||||||
|
runProdApi({
|
||||||
|
endpoint:
|
||||||
|
"/public/v1.0/IssueMaterial/ReturnPartiallyConsumedManualMaterial",
|
||||||
|
data: [matReturnData],
|
||||||
|
}),
|
||||||
|
)) as any;
|
||||||
|
|
||||||
|
if (matReturError) return matReturError;
|
||||||
|
return matReturn;
|
||||||
|
};
|
||||||
|
|
||||||
const transferMaterial = async (
|
const transferMaterial = async (
|
||||||
delay: number,
|
delay: number,
|
||||||
data: any,
|
data: any,
|
||||||
@@ -347,12 +361,13 @@ const transferMaterial = async (
|
|||||||
newQty: any,
|
newQty: any,
|
||||||
) => {
|
) => {
|
||||||
//console.log(data);
|
//console.log(data);
|
||||||
|
console.log("Transferring the material");
|
||||||
if (pendingJobs.has(data.runningNumber)) {
|
if (pendingJobs.has(data.runningNumber)) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"materials",
|
"materials",
|
||||||
"ocp",
|
"ocp",
|
||||||
`${data.runningNumber} is pending to be transfered already`,
|
`${data.runningNumber} is pending to be transferred already`,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const qualityCycle = async () => {
|
|||||||
db
|
db
|
||||||
.select()
|
.select()
|
||||||
.from(qualityRequest)
|
.from(qualityRequest)
|
||||||
.where(inArray(qualityRequest.palletStatus, [1, 4, 5, 6])),
|
.where(inArray(qualityRequest.palletStatus, [1, 4, 5, 6, 7])),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -64,6 +64,9 @@ export const qualityCycle = async () => {
|
|||||||
let prodData: any =
|
let prodData: any =
|
||||||
queryData?.data.length === 0 ? [] : queryData.data;
|
queryData?.data.length === 0 ? [] : queryData.data;
|
||||||
|
|
||||||
|
// if there isnt a pallet just continue
|
||||||
|
if (queryData?.data.length === 0) continue;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
lstQData[i]?.locationAtRequest != prodData[0]?.locationAtRequest
|
lstQData[i]?.locationAtRequest != prodData[0]?.locationAtRequest
|
||||||
) {
|
) {
|
||||||
@@ -71,7 +74,7 @@ export const qualityCycle = async () => {
|
|||||||
const qDataPost = {
|
const qDataPost = {
|
||||||
warehouseMovedTo: prodData[0]?.warehouseAtRequest,
|
warehouseMovedTo: prodData[0]?.warehouseAtRequest,
|
||||||
locationMovedTo: prodData[0]?.locationAtRequest,
|
locationMovedTo: prodData[0]?.locationAtRequest,
|
||||||
// how ling did it take the warehouse to originally move the pallet
|
// how long did it take the warehouse to originally move the pallet
|
||||||
durationToMove: warehouse.includes(lstQData[i].palletStatus)
|
durationToMove: warehouse.includes(lstQData[i].palletStatus)
|
||||||
? differenceInMinutes(
|
? differenceInMinutes(
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
|
|||||||
Reference in New Issue
Block a user