11import { IHttpClientResponse } from '@actions/http-client/interfaces'
2- import { isRetryableStatusCode , isSuccessStatusCode , sleep } from './utils'
2+ import {
3+ isRetryableStatusCode ,
4+ isSuccessStatusCode ,
5+ sleep ,
6+ getExponentialRetryTimeInMilliseconds
7+ } from './utils'
38import * as core from '@actions/core'
9+ import { getRetryLimit } from './config-variables'
410
511export async function retry < T > (
612 name : string ,
713 operation : ( ) => Promise < T > ,
814 getStatusCode : ( response : T ) => number | undefined ,
915 errorMessages : Map < number , string > ,
10- maxAttempts : number ,
11- delayMilliseconds : number
16+ maxAttempts : number
1217) : Promise < T > {
1318 let response : T | undefined = undefined
1419 let statusCode : number | undefined = undefined
@@ -47,7 +52,7 @@ export async function retry<T>(
4752 `${ name } - Attempt ${ attempt } of ${ maxAttempts } failed with error: ${ errorMessage } `
4853 )
4954
50- await sleep ( delayMilliseconds )
55+ await sleep ( getExponentialRetryTimeInMilliseconds ( attempt ) )
5156 attempt ++
5257 }
5358
@@ -61,14 +66,13 @@ export async function retryHttpClientRequest<T>(
6166 name : string ,
6267 method : ( ) => Promise < IHttpClientResponse > ,
6368 errorMessages : Map < number , string > = new Map ( ) ,
64- maxAttempts = 3
69+ maxAttempts = getRetryLimit ( )
6570) : Promise < IHttpClientResponse > {
6671 return await retry (
6772 name ,
6873 method ,
6974 ( response : IHttpClientResponse ) => response . message . statusCode ,
7075 errorMessages ,
71- maxAttempts ,
72- 5000
76+ maxAttempts
7377 )
7478}
0 commit comments