Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b54065b5da | ||
|
|
c33724abbd | ||
|
|
d6f3ee93b8 | ||
|
|
34a411f3c0 | ||
|
|
2d6ba67518 | ||
|
|
78ed49ff88 | ||
|
|
c119fcd773 | ||
|
|
73babeabef | ||
|
|
bf93b54558 | ||
|
|
0c0770ce57 | ||
|
|
571bf222ee |
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user