added polling api

This commit is contained in:
sumedh
2024-10-18 17:30:15 +05:30
parent 61cf99f410
commit f67ccf2c4a

View File

@@ -73,22 +73,9 @@
</socketManager> </socketManager>
<socketManager @update="handleCloneRepoWebSocketMessage" topic="topic" subtopic="deletion-status"> <socketManager @update="handleCloneRepoWebSocketMessage" topic="topic" subtopic="deletion-status">
</socketManager> </socketManager>
<!--Column field="id" header="KSGitInfoID" sortable /-->
<Column /> <Column />
<Column /> <Column />
<!--Column field="ksGitIngestionInfo.id" header="ksGitIngestionInfo" sortable> </Column-->
<!--Column field="repoName" header="Repo Name">
<template #body="{ data }">
{{ data.repoName }}
</template>
<template #filter="{ filterModel, filterCallback }">
<InputText v-model="filterModel.value" type="text" @input="filterCallback()"
placeholder="Search by Git Repo Name" />
</template>
</Column-->
<Column field="branch" header="Branch"> <Column field="branch" header="Branch">
<template #body="{ data }"> <template #body="{ data }">
@@ -257,7 +244,7 @@ const logoSrc = ref(logo);
onMounted(() => { onMounted(() => {
fetchCodeRepoInfo(); fetchCodeRepoInfo();
startPolling();
}); });
const refreshPage = () => { const refreshPage = () => {
@@ -279,18 +266,19 @@ const handleCloneRepoWebSocketMessage = (data) => {
}; };
//websocket end //websocket end
//polling //updateParsingProgress
const updateParsingProgress2 = async (data) => { const updateParsingProgress = async (data) => {
const updatedData = await Promise.all((data || []).map(async (d) => { const updatedData = await Promise.all((data || []).map(async (d) => {
if (d.parseStatus == "IN PROGRESS") { if (d.parseStatus === "IN PROGRESS") {
try { try {
const parseResponse = await axios.get(`/get-parse-status?id=${d.parseId}`) const parseResponse = await axios.get(`/get-parse-status?id=${d.parseId}`);
console.log("parseResponse: ", parseResponse.data);
d.parseInfo = parseResponse.data; d.parseInfo = parseResponse.data;
} catch (error) { } catch (error) {
console.error("Error fetching parse status:", error); console.error("Error fetching parse status:", error);
d.parseInfo = { totalFiles: 0, parsedFiles: 0 }; d.parseInfo = { totalFiles: 0, parsedFiles: 0 };
}; }
} else if (d.parseStatus === "DONE") {
d.parseInfo = { totalFiles: 1, parsedFiles: 1 };
} else { } else {
d.parseInfo = { totalFiles: 0, parsedFiles: 0 }; d.parseInfo = { totalFiles: 0, parsedFiles: 0 };
} }
@@ -298,20 +286,35 @@ const updateParsingProgress2 = async (data) => {
})); }));
return updatedData; return updatedData;
}; };
const updateParsingProgress = async () => {
//polling
// Function to start polling
let pollingInterval = null;
function startPolling() {
// Set polling interval (every 5 seconds in this case)
pollingInterval = setInterval(pollBackendAPI, 10000);
console.log("Polling started.");
}
// Function to stop polling
function stopPolling() {
clearInterval(pollingInterval);
console.log("All parseStatus are DONE, polling stopped.");
}
const pollBackendAPI = () => {
for (let i = 0; i < codeRepoInfo.value.length; i++) { for (let i = 0; i < codeRepoInfo.value.length; i++) {
if (codeRepoInfo.value[i].parseStatus == "IN PROGRESS" && codeRepoInfo.value[i].id != '6710d7eda8050cb3b2d088a0') { // Check if all parseStatus are DONE or ERROR
axios.get(`/get-parse-status?id=${codeRepoInfo.value[i].parseId}`) const allDoneOrError = codeRepoInfo.value.every(repo => repo.parseStatus === 'DONE');
.then(parseResponse => { if (allDoneOrError) {
console.log("parseResponse: ", parseResponse.data) stopPolling();
codeRepoInfo.value[i].parseInfo = parseResponse.data; return; //exit from loop
})
.catch(error => {
console.error("Error fetching parse status:", error);
});
} else {
codeRepoInfo.value[i].parseInfo = { totalFiles: 101, parsedFiles: 101 };
} }
else if (codeRepoInfo.value[i].parseStatus === 'IN PROGRESS' || codeRepoInfo.value[i].parseStatus === 'ERROR') {
fetchCodeRepoInfo();
console.log("Condition met");
return; //exit from loop
}
} }
}; };
@@ -340,17 +343,10 @@ function calculateCustomerTotal(name) {
const fetchCodeRepoInfo = async () => { const fetchCodeRepoInfo = async () => {
try { try {
const response = await axios.get('/fe-api/ks_git_repos'); const response = await axios.get('/fe-api/ks_git_repos');
//codeRepoInfo.value = response.data; //console.log(response.data);
console.log(response.data);
const filterDate = getCustomDatewithAllResponse(response.data); const filterDate = getCustomDatewithAllResponse(response.data);
const filterParseEnabled = getCustomJsonWithJavaParseEnabled(filterDate); const filterParseEnabled = getCustomJsonWithJavaParseEnabled(filterDate);
const addParseInfo = await updateParsingProgress2(filterParseEnabled); codeRepoInfo.value = await updateParsingProgress(filterParseEnabled);
//console.log("updateParsingProgress2 : ", updateParsingProgress2(codeRepoInfo.value));
console.log("**************")
console.log("addParseInfo : ", addParseInfo);
codeRepoInfo.value = addParseInfo;
console.log("codeRepoInfo.value : ", codeRepoInfo.value);
//updateParsingProgress();
loading.value = false; loading.value = false;
} catch (error) { } catch (error) {
console.error('Failed to fetch code repo info:', error); console.error('Failed to fetch code repo info:', error);
@@ -369,7 +365,7 @@ const getCustomJsonWithJavaParseEnabled = (data) => {
}; };
//ingest git repo functions //parse git repo functions
const parseGitRepo = (data) => { const parseGitRepo = (data) => {
console.log(data) console.log(data)
const requestBody = { const requestBody = {