@@ -63,14 +63,14 @@ import {
6363 AppGroupDetailDefaultType ,
6464 BulkCDDetailType ,
6565 BulkCIDetailType ,
66+ ProcessWorkFlowStatusType ,
6667 ResponseRowType ,
6768 WorkflowAppSelectionType ,
6869 WorkflowNodeSelectionType ,
6970} from '../../AppGroup.types'
7071import { handleSourceNotConfigured , processWorkflowStatuses } from '../../AppGroup.utils'
7172import Tippy from '@tippyjs/react'
7273
73- let timerRef
7474let inprogressStatusTimer
7575export default function EnvTriggerView ( { filteredApps } : AppGroupDetailDefaultType ) {
7676 const { envId } = useParams < { envId : string } > ( )
@@ -131,17 +131,23 @@ export default function EnvTriggerView({ filteredApps }: AppGroupDetailDefaultTy
131131 setErrorCode ( 0 )
132132 setPageViewType ( ViewType . FORM )
133133 getWorkflowStatusData ( _workflows )
134- timerRef && clearInterval ( timerRef )
135- timerRef = setInterval ( ( ) => {
136- getWorkflowStatusData ( _workflows )
137- } , 30000 )
138134 } catch ( error ) {
139135 showError ( error )
140136 setErrorCode ( error [ 'code' ] )
141137 setPageViewType ( ViewType . ERROR )
142138 }
143139 }
144140
141+ const pollWorkflowStatus = ( _processedWorkflowsData : ProcessWorkFlowStatusType ) => {
142+ inprogressStatusTimer && clearTimeout ( inprogressStatusTimer )
143+ inprogressStatusTimer = setTimeout (
144+ ( ) => {
145+ getWorkflowStatusData ( _processedWorkflowsData . workflows )
146+ } ,
147+ _processedWorkflowsData . cicdInProgress ? 10000 : 30000 ,
148+ )
149+ }
150+
145151 const getWorkflowStatusData = ( workflowsList : WorkflowType [ ] ) => {
146152 getWorkflowStatus ( envId )
147153 . then ( ( response ) => {
@@ -150,16 +156,13 @@ export default function EnvTriggerView({ filteredApps }: AppGroupDetailDefaultTy
150156 response ?. result ?. cdWorkflowStatus ?? [ ] ,
151157 workflowsList ,
152158 )
153- inprogressStatusTimer && clearTimeout ( inprogressStatusTimer )
154- if ( _processedWorkflowsData . cicdInProgress ) {
155- inprogressStatusTimer = setTimeout ( ( ) => {
156- getWorkflowStatusData ( _processedWorkflowsData . workflows )
157- } , 10000 )
158- }
159+ pollWorkflowStatus ( _processedWorkflowsData )
159160 setWorkflows ( _processedWorkflowsData . workflows )
160161 } )
161162 . catch ( ( errors : ServerErrors ) => {
162163 showError ( errors )
164+ // If ci cd is in progress then call the api after every 10sec
165+ pollWorkflowStatus ( { cicdInProgress : true , workflows : workflowsList } )
163166 } )
164167 }
165168
@@ -170,7 +173,6 @@ export default function EnvTriggerView({ filteredApps }: AppGroupDetailDefaultTy
170173 getWorkflowsData ( )
171174 }
172175 return ( ) => {
173- timerRef && clearInterval ( timerRef )
174176 inprogressStatusTimer && clearTimeout ( inprogressStatusTimer )
175177 }
176178 } , [ envId ] )
0 commit comments