Skip to content

Commit 26d7b84

Browse files
committed
fix: polling cleanup in external apps
1 parent c5dfd7a commit 26d7b84

File tree

3 files changed

+68
-31
lines changed

3 files changed

+68
-31
lines changed

src/components/externalArgoApps/ExternalArgoAppDetail.tsx

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

6969
const _init = () => {
7070
if (!isAPICallInProgress) {
71-
_getAndSetAppDetail(true)
71+
_getAndSetAppDetail()
7272
}
7373
}
7474

75-
const _getAndSetAppDetail = async (shouldTriggerPolling: boolean = false) => {
75+
const handleInitiatePolling = () => {
76+
if (initTimer) {
77+
clearTimeout(initTimer)
78+
}
79+
80+
initTimer = setTimeout(() => {
81+
_init()
82+
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
83+
}
84+
85+
const _getAndSetAppDetail = async () => {
7686
isAPICallInProgress = true
7787
setIsReloadResourceTreeInProgress(true)
7888

@@ -85,25 +95,25 @@ const ExternalArgoAppDetail = ({ appName, clusterId, isExternalApp, namespace }:
8595
...appDetailResponse.result,
8696
deploymentAppType: DeploymentAppTypes.GITOPS,
8797
}
98+
99+
isAPICallInProgress = false
100+
handleInitiatePolling()
101+
88102
IndexStore.publishAppDetails(genericAppDetail, AppType.EXTERNAL_ARGO_APP)
89103
setErrorResponseCode(undefined)
90104
})
91105
.catch((errors: ServerErrors) => {
92106
if (!getIsRequestAborted(errors)) {
93107
showError(errors)
94108
setErrorResponseCode(errors.code)
109+
isAPICallInProgress = false
110+
handleInitiatePolling()
95111
}
96112
})
97113
.finally(() => {
98114
setIsLoading(false)
99115
isAPICallInProgress = false
100116
setIsReloadResourceTreeInProgress(false)
101-
102-
if (shouldTriggerPolling) {
103-
initTimer = setTimeout(() => {
104-
_init()
105-
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
106-
}
107117
})
108118
}
109119

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

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

8181
const _init = () => {
8282
if (!isAPICallInProgress) {
83-
_getAndSetAppDetail(true)
83+
_getAndSetAppDetail()
8484
}
8585
}
8686

@@ -120,7 +120,17 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
120120
return genericAppDetail
121121
}
122122

123-
const _getAndSetAppDetail = (shouldTriggerPolling: boolean = false) => {
123+
const handleInitiatePolling = () => {
124+
if (initTimer) {
125+
clearTimeout(initTimer)
126+
}
127+
128+
initTimer = setTimeout(() => {
129+
_init()
130+
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
131+
}
132+
133+
const _getAndSetAppDetail = () => {
124134
isAPICallInProgress = true
125135
setIsReloadResourceTreeInProgress(true)
126136

@@ -161,24 +171,21 @@ const ExternalAppDetail = ({ appId, appName, isExternalApp }) => {
161171
}
162172

163173
setErrorResponseCode(undefined)
174+
175+
handleInitiatePolling()
164176
})
165177
.catch((errors: ServerErrors) => {
178+
setIsLoading(false)
179+
isAPICallInProgress = false
180+
166181
if (!getIsRequestAborted(errors)) {
167182
showError(errors)
168183
setErrorResponseCode(errors.code)
184+
handleInitiatePolling()
169185
}
170-
171-
setIsLoading(false)
172-
isAPICallInProgress = false
173186
})
174187
.finally(() => {
175188
setIsReloadResourceTreeInProgress(false)
176-
177-
if (shouldTriggerPolling) {
178-
initTimer = setTimeout(() => {
179-
_init()
180-
}, window._env_.EA_APP_DETAILS_POLLING_INTERVAL || 30000)
181-
}
182189
})
183190
}
184191

src/components/v2/index.tsx

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

118118
const _init = (fetchExternalLinks?: boolean) => {
119-
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks, true), abortControllerRef)
119+
abortPreviousRequests(() => _getAndSetAppDetail(fetchExternalLinks), abortControllerRef)
120120
}
121121

122122
const handleAppDetailsCallError = (e: any) => {
@@ -141,12 +141,16 @@ const RouterComponent = ({ envType }) => {
141141
}
142142

143143
const handleInitiatePolling = () => {
144+
if (initTimer) {
145+
clearTimeout(initTimer)
146+
}
147+
144148
initTimer = setTimeout(() => {
145149
_init()
146150
}, window._env_.HELM_APP_DETAILS_POLLING_INTERVAL || 30000)
147151
}
148152

149-
const handleFetchAppDetails = async (fetchExternalLinks: boolean) => {
153+
const handleFetchAppDetails = async (fetchExternalLinks: boolean): Promise<{ isAborted: boolean }> => {
150154
try {
151155
const response = await getInstalledChartDetail(+params.appId, +params.envId, abortControllerRef)
152156
handlePublishAppDetails(response)
@@ -155,32 +159,49 @@ const RouterComponent = ({ envType }) => {
155159
if (fetchExternalLinks) {
156160
getExternalLinksAndTools(response.result?.clusterId)
157161
}
162+
setLoadingDetails(false)
158163
} catch (error) {
159-
handleAppDetailsCallError(error)
160-
} finally {
164+
const isAborted = getIsRequestAborted(error)
165+
166+
if (!isAborted) {
167+
handleAppDetailsCallError(error)
168+
}
161169
setLoadingDetails(false)
170+
171+
return { isAborted }
162172
}
173+
174+
return { isAborted: false }
163175
}
164176

165177
const handleFetchResourceTree = async () => {
166178
try {
167179
const response = await getInstalledChartResourceTree(+params.appId, +params.envId, abortControllerRef)
168180
handlePublishAppDetails(response)
181+
setLoadingResourceTree(false)
169182
} catch (error) {
170-
handleAppDetailsCallError(error)
171-
} finally {
183+
const isAborted = getIsRequestAborted(error)
184+
185+
if (!isAborted) {
186+
handleAppDetailsCallError(error)
187+
}
172188
setLoadingResourceTree(false)
189+
190+
return { isAborted }
173191
}
192+
193+
return { isAborted: false }
174194
}
175195

176-
const _getAndSetAppDetail = async (fetchExternalLinks: boolean, shouldTriggerPolling: boolean = false) => {
196+
const _getAndSetAppDetail = async (fetchExternalLinks: boolean) => {
177197
if (envType === EnvType.CHART) {
178198
// Intentionally not setting await since it was not awaited earlier when in thens as well
179199
Promise.allSettled([
180200
handleFetchAppDetails(fetchExternalLinks),
181201
handleFetchResourceTree(),
182-
]).finally(() => {
183-
if (shouldTriggerPolling) {
202+
]).then((results) => {
203+
const isAborted = results.some((result) => result.status === 'fulfilled' && result.value.isAborted)
204+
if (!isAborted) {
184205
handleInitiatePolling()
185206
}
186207
})
@@ -195,9 +216,8 @@ const RouterComponent = ({ envType }) => {
195216
setErrorResponseCode(e.code)
196217
}
197218
} finally {
198-
if (shouldTriggerPolling) {
199-
handleInitiatePolling()
200-
}
219+
// BTW This is a dead block BTW should be removed
220+
handleInitiatePolling()
201221
}
202222
}
203223
}

0 commit comments

Comments
 (0)