@@ -96,20 +96,49 @@ const getStackByName = async (stackName: string, region: string) => {
9696 }
9797} ;
9898
99- const getStackActionResult = async ( stackId : string , region : string ) => {
99+ const getStackActionResult = async (
100+ stackId : string ,
101+ region : string ,
102+ ) : Promise < { stackName : string ; stackId : string } | undefined > => {
100103 return new Promise ( ( resolve , reject ) => {
104+ const startTime = Date . now ( ) ;
101105 const interval = setInterval ( async ( ) => {
102106 try {
103- const result = await client . getStack (
104- new GetStackRequest ( {
105- regionId : region ,
106- stackId,
107- } ) ,
108- ) ;
109- logger . info ( `stack status: ${ result . body ?. stackStatus } ` ) ;
110- if ( result . body ?. stackStatus ?. indexOf ( 'IN_PROGRESS' ) < 0 ) {
107+ const result = await client . getStack ( new GetStackRequest ( { regionId : region , stackId } ) ) ;
108+ const status = result . body ?. status ?? '' ;
109+
110+ logger . info ( `stack status: ${ status } ` ) ;
111+
112+ if (
113+ [
114+ 'CREATE_COMPLETE' ,
115+ 'UPDATE_COMPLETE' ,
116+ 'DELETE_COMPLETE' ,
117+ 'CHECK_COMPLETE' ,
118+ 'IMPORT_CREATE_COMPLETE' ,
119+ 'IMPORT_UPDATE_COMPLETE' ,
120+ ] . includes ( status )
121+ ) {
122+ clearInterval ( interval ) ;
123+ resolve ( result . body as { stackName : string ; stackId : string } ) ;
124+ } else if (
125+ [
126+ 'CREATE_ROLLBACK_FAILED' ,
127+ 'CREATE_ROLLBACK_COMPLETE' ,
128+ 'ROLLBACK_FAILED' ,
129+ 'ROLLBACK_COMPLETE' ,
130+ 'IMPORT_CREATE_ROLLBACK_FAILED' ,
131+ 'IMPORT_CREATE_ROLLBACK_COMPLETE' ,
132+ 'IMPORT_UPDATE_ROLLBACK_FAILED' ,
133+ 'IMPORT_UPDATE_ROLLBACK_COMPLETE' ,
134+ ] . includes ( status )
135+ ) {
136+ clearInterval ( interval ) ;
137+ reject ( new Error ( `Stack operation failed with status: ${ status } ` ) ) ;
138+ } else if ( Date . now ( ) - startTime > 3600000 ) {
139+ // 1 hour in milliseconds
111140 clearInterval ( interval ) ;
112- resolve ( result . body ) ;
141+ reject ( new Error ( 'Stack operation did not finish within 1 hour' ) ) ;
113142 }
114143 } catch ( error ) {
115144 clearInterval ( interval ) ;
@@ -128,19 +157,18 @@ export const rosStackDeploy = async (
128157 if ( stackInfo ) {
129158 const { Status : stackStatus } = stackInfo ;
130159 if ( stackStatus ?. indexOf ( 'IN_PROGRESS' ) >= 0 ) {
131- logger . error ( `fail to update stack, because stack status is ${ stackStatus } ` ) ;
132160 throw new Error ( `fail to update stack, because stack status is ${ stackStatus } ` ) ;
133161 }
134162
135163 logger . info ( `Update stack: ${ stackName } deploying... ` ) ;
136164 const stack = await updateStack ( stackInfo . stackId as string , templateBody , context ) ;
137165
138- logger . info ( `updateStack: ${ JSON . stringify ( stack ) } ` ) ;
166+ logger . info ( `stackUpdate success! stackName: ${ stack ?. stackName } , stackId: ${ stack ?. stackId } ` ) ;
139167 } else {
140168 // create stack
141169 logger . info ( `Create stack: ${ stackName } deploying... ` ) ;
142170 const stack = await createStack ( stackName , templateBody , context ) ;
143171
144- logger . info ( `createStack: ${ JSON . stringify ( stack ) } ` ) ;
172+ logger . info ( `createStack success! stackName: ${ stack ?. stackName } , stackId: ${ stack ?. stackId } ` ) ;
145173 }
146174} ;
0 commit comments