@@ -506,26 +506,39 @@ export class WarpBuildRemoteBuilders {
506506
507507 public async removeBuilderInstances ( ) : Promise < void > {
508508 for ( const builderInstance of this . builderInstances ) {
509- try {
510- core . info ( `Removing builder instance ${ builderInstance . id } request ${ builderInstance . request_id } ` ) ;
511- const removeBuilderEndpoint = `${ this . apiDomain } /api/v1/builder-session-requests/complete` ;
512- const authHeader = this . isWarpBuildRunner ? `Bearer ${ process . env . WARPBUILD_RUNNER_VERIFICATION_TOKEN } ` : `Bearer ${ this . apiKey } ` ;
513-
514- const response = await fetch ( removeBuilderEndpoint , {
515- method : 'POST' ,
516- headers : { Authorization : authHeader } ,
517- body : JSON . stringify ( { request_id : builderInstance . request_id , external_unique_id : this . idempotencyKey } )
518- } ,
519- ) ;
509+ let retryCount = 0 ;
510+ const maxRetries = 2 ;
511+
512+ while ( retryCount <= maxRetries ) {
513+ try {
514+ core . info ( `Removing builder instance ${ builderInstance . id } request ${ builderInstance . request_id } ${ retryCount > 0 ? ` (retry ${ retryCount } )` : '' } ` ) ;
515+ const removeBuilderEndpoint = `${ this . apiDomain } /api/v1/builder-session-requests/complete` ;
516+ const authHeader = this . isWarpBuildRunner ? `Bearer ${ process . env . WARPBUILD_RUNNER_VERIFICATION_TOKEN } ` : `Bearer ${ this . apiKey } ` ;
517+
518+ const response = await fetch ( removeBuilderEndpoint , {
519+ method : 'POST' ,
520+ headers : { Authorization : authHeader } ,
521+ body : JSON . stringify ( { request_id : builderInstance . request_id , external_unique_id : this . idempotencyKey } )
522+ } ,
523+ ) ;
524+
525+ if ( ! response . ok ) {
526+ const errorData = await response . json ( ) . catch ( ( ) => ( { message : 'Unknown error' } ) ) ;
527+ throw new Error ( `Failed to remove builder instance: ${ errorData . description || errorData . message || 'Unknown error' } ` ) ;
528+ }
520529
521- if ( ! response . ok ) {
522- const errorData = await response . json ( ) . catch ( ( ) => ( { message : 'Unknown error' } ) ) ;
523- throw new Error ( `Failed to remove builder instance: ${ errorData . description || errorData . message || 'Unknown error' } ` ) ;
530+ core . info ( `Builder instance ${ builderInstance . id } removed successfully` ) ;
531+ break ; // Success, exit retry loop
532+ } catch ( error ) {
533+ retryCount ++ ;
534+ if ( retryCount > maxRetries ) {
535+ core . warning ( `Failed to remove builder request ${ builderInstance . request_id } after ${ maxRetries + 1 } attempts: ${ error . message } ` ) ;
536+ } else {
537+ core . warning ( `Failed to remove builder request ${ builderInstance . request_id } (attempt ${ retryCount } ), retrying...` ) ;
538+ // Wait a bit before retrying
539+ await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
540+ }
524541 }
525-
526- core . info ( `Builder instance ${ builderInstance . id } removed successfully` ) ;
527- } catch ( error ) {
528- core . warning ( `Failed to remove builder request ${ builderInstance . request_id } : ${ error . message } ` ) ;
529542 }
530543 }
531544 }
0 commit comments