Add add all to dev menu, hot reloading for main, and log cleanup.
This commit is contained in:
@@ -41,6 +41,7 @@ import DecodeTtl from "./decode-ttl";
|
||||
import { DecodedTtl } from "./decode-ttl.interface";
|
||||
import DecodeVeh from "./decode-veh";
|
||||
import { DecodedVeh } from "./decode-veh.interface";
|
||||
import { platform } from "@electron-toolkit/utils";
|
||||
|
||||
async function ImportJob(filepath: string): Promise<void> {
|
||||
const parsedFilePath = path.parse(filepath);
|
||||
@@ -51,6 +52,8 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
log.debug("Importing Job", extensionlessFilePath);
|
||||
|
||||
try {
|
||||
await WaitForAllFiles(extensionlessFilePath, requiredExtensions);
|
||||
|
||||
//The below all end up returning parts of the job object.
|
||||
//Some of them return additional info - e.g. owner or vehicle record data at both the job and corresponding table level.
|
||||
const env: DecodedEnv = await DecodeEnv(extensionlessFilePath);
|
||||
@@ -154,6 +157,9 @@ async function ImportJob(filepath: string): Promise<void> {
|
||||
log.info(`Job data saved to: ${filePath}`);
|
||||
}
|
||||
|
||||
//Temporarily adjust the claim number to ensure we are running on the right set of claims.
|
||||
jobObject.clm_no = `ELECTRONAPP-${jobObject.clm_no}`;
|
||||
|
||||
const newAvailableJob: AvailableJobSchema = {
|
||||
uploaded_by: store.get("user.email"),
|
||||
bodyshopid: store.get("app.bodyshop.id"),
|
||||
@@ -251,3 +257,86 @@ export interface AvailableJobSchema {
|
||||
issupplement: boolean;
|
||||
jobid: UUID | null;
|
||||
}
|
||||
|
||||
async function WaitForAllFiles(
|
||||
baseFilePath: string,
|
||||
requiredExtensions: string[],
|
||||
maxRetries: number = 5,
|
||||
backoffMs: number = 1000,
|
||||
): Promise<void> {
|
||||
if (platform.isWindows) {
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
const missingFiles = requiredExtensions.filter((ext) => {
|
||||
const filePath = `${baseFilePath}.${ext}`;
|
||||
const filePathA = `${baseFilePath}A.${ext}`;
|
||||
const filePathB = `${baseFilePath}B.${ext}`;
|
||||
const filePathV = `${baseFilePath}V.${ext}`;
|
||||
return !(
|
||||
fs.existsSync(filePath) ||
|
||||
fs.existsSync(filePathA) ||
|
||||
fs.existsSync(filePathB) ||
|
||||
fs.existsSync(filePathV)
|
||||
);
|
||||
});
|
||||
|
||||
if (missingFiles.length === 0) {
|
||||
return; // All files are present
|
||||
}
|
||||
|
||||
log.debug(
|
||||
`Attempt ${attempt}: Missing files: ${missingFiles.join(", ")}. Retrying in ${backoffMs}ms...`,
|
||||
);
|
||||
|
||||
if (attempt < maxRetries) {
|
||||
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
||||
backoffMs *= 2; // Exponential backoff
|
||||
} else {
|
||||
throw new Error(
|
||||
`The set of files is not valid. Missing files for CIECA ID ${baseFilePath}: ${missingFiles.join(", ")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Linux and MacOS are case sensitive
|
||||
//TODO: Implement case insensitivity.
|
||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||
const missingFiles = requiredExtensions.filter((ext) => {
|
||||
const filePath = `${baseFilePath}.${ext}`;
|
||||
return !fs.existsSync(filePath);
|
||||
});
|
||||
|
||||
if (missingFiles.length === 0) {
|
||||
return; // All files are present
|
||||
}
|
||||
|
||||
log.debug(
|
||||
`Attempt ${attempt}: Missing files: ${missingFiles.join(", ")}. Retrying in ${backoffMs}ms...`,
|
||||
);
|
||||
|
||||
if (attempt < maxRetries) {
|
||||
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
||||
backoffMs *= 2; // Exponential backoff
|
||||
} else {
|
||||
throw new Error(
|
||||
`The set of files is not valid. Missing files for CIECA ID ${baseFilePath}: ${missingFiles.join(", ")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const requiredExtensions = [
|
||||
"env",
|
||||
"ad1",
|
||||
"ad2",
|
||||
"veh",
|
||||
"lin",
|
||||
"pfh",
|
||||
"pfl",
|
||||
"pft",
|
||||
"pfm",
|
||||
"pfo",
|
||||
"stl",
|
||||
"ttl",
|
||||
"pfp",
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user