Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLM-6225_added time out according to data #855

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
const { data: Schemas, isLoading: isThisLoading } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "adminSchema" }]);

const { data: readMe } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "ReadMeConfig" }]);
const { data: baseTimeOut } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "baseTimeOut" }]);
const [sheetHeaders, setSheetHeaders] = useState({});
const [translatedSchema, setTranslatedSchema] = useState({});
const [readMeInfo, setReadMeInfo] = useState({});
Expand Down Expand Up @@ -711,13 +712,14 @@ const UploadData = ({ formData, onSelect, ...props }) => {
setIsError(true);

try {
const temp = await Digit.Hooks.campaign.useResourceData(uploadedFile, params?.hierarchyType, type, tenantId, id);
const temp = await Digit.Hooks.campaign.useResourceData(uploadedFile, params?.hierarchyType, type, tenantId, id , baseTimeOut?.["HCM-ADMIN-CONSOLE"]?.baseTimeOut?.[0]?.baseTimeOut);
if (temp?.isError) {
setIsValidation(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper error handling is implemented by checking the isError property of the response. However, consider adding more detailed logging or error tracking for better debugging and maintenance.

+ console.error("Validation error:", errorMessage);

Also applies to: 722-722

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setIsValidation(false);
setIsValidation(false);
console.error("Validation error:", errorMessage);

const errorMessage = temp?.error.replaceAll(":", "-");
setShowToast({ key: "error", label: errorMessage, transitionTime: 5000000 });
setIsError(true);
setApiError(errorMessage);
setIsValidation(false);

return;
}
if (temp?.status === "completed") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const baseTimeOut =
{
baseTimeOut: 100
};

Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
export const useResourceData = async (data, hierarchyType, type, tenantId, id) => {
import axios from 'axios';
import * as XLSX from 'xlsx';
import { baseTimeOut } from '../configs/baseTimeOut';
export const useResourceData = async (data, hierarchyType, type, tenantId, id , baseTimeOut) => {


let Type;
let jsonDataLength;
let Error = {
isError: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name Error shadows a global property. Consider renaming it to avoid confusion and potential bugs.

- let Error = {
+ let errorDetails = {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let Error = {
let errorDetails = {
Tools
Biome

[error] 9-9: Do not shadow the global "Error" property. (lint/suspicious/noShadowRestrictedNames)

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

error: {},
Expand All @@ -13,6 +19,29 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) =
Type = "boundaryWithTarget";
}
try {
if(data){
axios
.get("/filestore/v1/files/id", {
responseType: "arraybuffer",
headers: {
"Content-Type": "application/json",
Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"auth-token": Digit.UserService.getUser()?.["access_token"],
},
params: {
tenantId: Digit.ULBService.getCurrentTenantId(),
fileStoreId: data?.[0]?.filestoreId,
},
})
.then(async (res) => {
const fileData = res.data;
const workbook = XLSX.read(fileData, { type: 'buffer' });
const sheetName = workbook.SheetNames[1];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet);
jsonDataLength = jsonData.length;
});
}
const responseTemp = await Digit.CustomService.getResponse({
url: "/project-factory/v1/data/_create",
body: {
Expand All @@ -27,7 +56,9 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) =
},
},
});

response = responseTemp;

} catch (error) {
if (error?.response && error?.response?.data) {
const errorMessage = error?.response?.data?.Errors?.[0]?.message;
Expand All @@ -46,6 +77,10 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) =

let searchResponse;
let status = "validation-started";
const baseDelay = baseTimeOut;
let retryInterval = baseDelay * jsonDataLength;

await new Promise((resolve) => setTimeout(resolve, retryInterval));

// Retry until a response is received
while (status !== "failed" && status !== "invalid" && status !== "completed") {
Expand All @@ -61,7 +96,8 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) =
});
status = searchResponse?.ResourceDetails?.[0]?.status;
if (status !== "failed" && status !== "invalid" && status !== "completed") {
await new Promise((resolve) => setTimeout(resolve, 5000));
retryInterval *= 2;
await new Promise((resolve) => setTimeout(resolve, retryInterval));
}
}
if (Error.isError) {
Expand Down
Loading