Compare commits

...
Author SHA1 Message Date
Vallie Joseph b54065b5da making a promise array 2023-12-20 21:15:04 +00:00
srryan c33724abbd update to http client 2023-12-20 15:45:19 -05:00
Rob Herley d6f3ee93b8 reject don't throw 2023-12-20 14:37:13 -05:00
Rob Herley 34a411f3c0 add timeout in between data chunks 2023-12-20 13:59:31 -05:00
Rob Herley 2d6ba67518 retry the promise 2023-12-20 13:11:04 -05:00
srryan 78ed49ff88 update error handling abort 2023-12-19 12:46:58 -05:00
srryan c119fcd773 update optional settings for blob client 2023-12-19 12:02:10 -05:00
srryan 73babeabef add explicit options 2023-12-19 11:49:39 -05:00
Vallie Joseph bf93b54558 adding logger for blob client and response 2023-12-18 23:09:10 +00:00
srryan 0c0770ce57 cleanup 2023-12-18 17:52:55 -05:00
srryan 571bf222ee update to use blob client over http client 2023-12-18 17:11:14 -05:00
@@ -38,6 +38,36 @@ async function exists(path: string): Promise<boolean> {
}
async function streamExtract(url: string, directory: string): Promise<void> {
let retryCount = 0
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const promises: Promise<any>[] = []
while (retryCount < 5) {
const promise = new Promise(async () => {
try {
await streamExtractInternal(url, directory)
} catch (err) {
retryCount++
core.warning(`Failed to download artifact. Retrying in 5 seconds...`)
await new Promise(resolve => setTimeout(resolve, 5000))
}
})
promises.push(promise)
}
try {
await Promise.all(promises)
core.info('All Promises Returned')
} catch (error) {
throw new Error(`Artifact download failed after ${retryCount} retries.`)
}
// throw new Error(`Artifact download failed after ${retryCount} retries.`)
}
async function streamExtractInternal(
url: string,
directory: string
): Promise<void> {
const client = new httpClient.HttpClient(getUserAgentString())
const response = await client.get(url)
@@ -48,10 +78,34 @@ async function streamExtract(url: string, directory: string): Promise<void> {
}
return new Promise((resolve, reject) => {
response.message
.pipe(unzip.Extract({path: directory}))
.on('close', resolve)
.on('error', reject)
const zipStream = unzip.Extract({path: directory})
const timeout = 30 * 1000
const timerFn = (): void => {
zipStream.end()
reject(new Error(`Blob storage chunk did not respond in ${timeout}ms `))
}
let timer = setTimeout(timerFn, timeout)
try {
response.message
.on('data', () => {
clearTimeout(timer)
timer = setTimeout(timerFn, timeout)
})
.pipe(zipStream)
.on('close', () => {
core.debug(`zip stream: Artifact downloaded to: ${directory}`)
clearTimeout(timer)
resolve()
})
.on('error', reject)
} catch (error) {
zipStream.end()
reject(error)
} finally {
clearTimeout(timer)
}
})
}