Skip to content

Commit 6d339bf

Browse files
committed
feat: initiate polling after is received instead of initiating on interval basis
1 parent d824fd5 commit 6d339bf

File tree

3 files changed

+64
-37
lines changed

3 files changed

+64
-37
lines changed

src/components/externalArgoApps/ExternalArgoAppDetail.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,11 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
6868

6969
const _init = () => {
7070
if (!isAPICallInProgress) {
71-
_getAndSetAppDetail()
71+
_getAndSetAppDetail(true)
7272
}
73-
initTimer = setTimeout(() => {
74-
_init()
75-
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
7673
}
7774

78-
const _getAndSetAppDetail = async () => {
75+
const _getAndSetAppDetail = async (shouldTriggerPolling: boolean = false) => {
7976
isAPICallInProgress = true
8077
setIsReloadResourceTreeInProgress(true)
8178

@@ -101,6 +98,12 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
10198
setIsLoading(false)
10299
isAPICallInProgress = false
103100
setIsReloadResourceTreeInProgress(false)
101+
102+
if (shouldTriggerPolling) {
103+
initTimer = setTimeout(() => {
104+
_init()
105+
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
106+
}
104107
})
105108
}
106109

src/components/v2/appDetails/ea/EAAppDetail.component.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
8080

8181
const _init = () => {
8282
if (!isAPICallInProgress) {
83-
_getAndSetAppDetail()
83+
_getAndSetAppDetail(true)
8484
}
85-
initTimer = setTimeout(() => {
86-
_init()
87-
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
8885
}
8986

9087
const _convertToGenericAppDetailModel = (
@@ -123,7 +120,7 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
123120
return genericAppDetail
124121
}
125122

126-
const _getAndSetAppDetail = () => {
123+
const _getAndSetAppDetail = (shouldTriggerPolling: boolean = false) => {
127124
isAPICallInProgress = true
128125
setIsReloadResourceTreeInProgress(true)
129126

@@ -176,6 +173,12 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
176173
})
177174
.finally(() => {
178175
setIsReloadResourceTreeInProgress(false)
176+
177+
if (shouldTriggerPolling) {
178+
initTimer = setTimeout(() => {
179+
_init()
180+
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
181+
}
179182
})
180183
}
181184

src/components/v2/index.tsx

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ const RouterComponent = ({ envType }) => {
116116
}, [location.search])
117117

118118
const _init = (fetchExternalLinks?: boolean) => {
119-
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks), abortControllerRef)
120-
initTimer = setTimeout(() => {
121-
_init()
122-
}, window._env_.HELM_APP_DETAILS_POLLING_INTERVAL || 30000)
119+
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks, true), abortControllerRef)
123120
}
124121

125122
const handleAppDetailsCallError = (e: any) => {
@@ -143,30 +140,50 @@ const RouterComponent = ({ envType }) => {
143140
setErrorResponseCode(undefined)
144141
}
145142

146-
const _getAndSetAppDetail = async (fetchExternalLinks: boolean) => {
147-
if (envType === EnvType.CHART) {
148-
// Get App Details
149-
getInstalledChartDetail(+params.appId, +params.envId, abortControllerRef)
150-
.then((response) => {
151-
handlePublishAppDetails(response)
152-
isVirtualRef.current = response.result?.isVirtualEnvironment
153-
setHelmAppPackageName(response.result?.helmPackageName)
154-
if (fetchExternalLinks) {
155-
getExternalLinksAndTools(response.result?.clusterId)
156-
}
157-
})
158-
.catch(handleAppDetailsCallError)
159-
.finally(() => {
160-
setLoadingDetails(false)
161-
})
143+
const handleInitiatePolling = () => {
144+
initTimer = setTimeout(() => {
145+
_init()
146+
}, window._env_.HELM_APP_DETAILS_POLLING_INTERVAL || 30000)
147+
}
162148

163-
// Get App Resource Tree
164-
getInstalledChartResourceTree(+params.appId, +params.envId, abortControllerRef)
165-
.then(handlePublishAppDetails)
166-
.catch(handleAppDetailsCallError)
167-
.finally(() => {
168-
setLoadingResourceTree(false)
169-
})
149+
const handleFetchAppDetails = async (fetchExternalLinks: boolean) => {
150+
try {
151+
const response = await getInstalledChartDetail(+params.appId, +params.envId, abortControllerRef)
152+
handlePublishAppDetails(response)
153+
isVirtualRef.current = response.result?.isVirtualEnvironment
154+
setHelmAppPackageName(response.result?.helmPackageName)
155+
if (fetchExternalLinks) {
156+
getExternalLinksAndTools(response.result?.clusterId)
157+
}
158+
} catch (error) {
159+
handleAppDetailsCallError(error)
160+
} finally {
161+
setLoadingDetails(false)
162+
}
163+
}
164+
165+
const handleFetchResourceTree = async () => {
166+
try {
167+
const response = await getInstalledChartResourceTree(+params.appId, +params.envId, abortControllerRef)
168+
handlePublishAppDetails(response)
169+
} catch (error) {
170+
handleAppDetailsCallError(error)
171+
} finally {
172+
setLoadingResourceTree(false)
173+
}
174+
}
175+
176+
const _getAndSetAppDetail = async (fetchExternalLinks: boolean, shouldTriggerPolling: boolean = false) => {
177+
if (envType === EnvType.CHART) {
178+
// Intentionally not setting await since it was not awaited earlier when in thens as well
179+
Promise.allSettled([
180+
handleFetchAppDetails(fetchExternalLinks),
181+
handleFetchResourceTree(),
182+
]).finally(() => {
183+
if (shouldTriggerPolling) {
184+
handleInitiatePolling()
185+
}
186+
})
170187
} else {
171188
try {
172189
// Revisit this flow
@@ -177,6 +194,10 @@ const RouterComponent = ({ envType }) => {
177194
if (e.code) {
178195
setErrorResponseCode(e.code)
179196
}
197+
} finally {
198+
if (shouldTriggerPolling) {
199+
handleInitiatePolling()
200+
}
180201
}
181202
}
182203
}

0 commit comments

Comments
 (0)