1
0
Fork 0

client fixes for retries + logging

pull/1613/head
srryan 2023-12-20 18:08:00 -05:00
parent c33724abbd
commit 03319fcffa
1 changed files with 31 additions and 31 deletions

View File

@ -17,6 +17,7 @@ import {
} from '../../generated' } from '../../generated'
import {getBackendIdsFromToken} from '../shared/util' import {getBackendIdsFromToken} from '../shared/util'
import {ArtifactNotFoundError} from '../shared/errors' import {ArtifactNotFoundError} from '../shared/errors'
import { clear } from 'console'
const scrubQueryParameters = (url: string): string => { const scrubQueryParameters = (url: string): string => {
const parsed = new URL(url) const parsed = new URL(url)
@ -41,11 +42,12 @@ async function streamExtract(url: string, directory: string): Promise<void> {
let retryCount = 0 let retryCount = 0
while (retryCount < 5) { while (retryCount < 5) {
try { try {
await streamExtractInternal(url, directory) await streamExtractInternal(url, directory)
return core.info(`Artifact downloaded successfully after ${retryCount} retries.`)
return
} catch (error) { } catch (error) {
retryCount++ retryCount++
core.warning(`Failed to download artifact. Retrying in 5 seconds...`) core.warning(`Failed to download artifact after ${retryCount} retries due to ${error.message}. Retrying in 5 seconds...`)
// wait 5 seconds before retrying // wait 5 seconds before retrying
await new Promise(resolve => setTimeout(resolve, 5000)) await new Promise(resolve => setTimeout(resolve, 5000))
} }
@ -54,10 +56,7 @@ async function streamExtract(url: string, directory: string): Promise<void> {
throw new Error(`Artifact download failed after ${retryCount} retries.`) throw new Error(`Artifact download failed after ${retryCount} retries.`)
} }
async function streamExtractInternal( async function streamExtractInternal(url: string,directory: string): Promise<void> {
url: string,
directory: string
): Promise<void> {
const client = new httpClient.HttpClient(getUserAgentString()) const client = new httpClient.HttpClient(getUserAgentString())
const response = await client.get(url) const response = await client.get(url)
@ -67,35 +66,35 @@ async function streamExtractInternal(
) )
} }
return new Promise((resolve, reject) => { const timeout = 30 * 1000 // 30 seconds
const zipStream = unzip.Extract({path: directory})
const timeout = 30 * 1000 return new Promise((resolve, reject) => {
const timerFn = (): void => { const timerFn = (): void => {
zipStream.end() // close response stream
reject(new Error(`Blob storage chunk did not respond in ${timeout}ms `)) core.warning("timerFn: closing response stream")
response.message.destroy(new Error(`Blob storage chunk did not respond in ${timeout}ms`))
} }
let timer = setTimeout(timerFn, timeout) let timer = setTimeout(timerFn, timeout)
try { response.message
response.message .on('data', () => {
.on('data', () => { timer.refresh()
clearTimeout(timer) })
timer = setTimeout(timerFn, timeout) .on('error', (error: Error) => {
}) core.warning(`response.message: Artifact download failed: ${error.message}`)
.pipe(zipStream) clearTimeout(timer)
.on('close', () => { reject(error)
core.debug(`zip stream: Artifact downloaded to: ${directory}`) })
clearTimeout(timer) .pipe(unzip.Extract({path: directory}))
resolve() .on('close', () => {
}) core.info(`zip stream: Artifact downloaded to: ${directory}`)
.on('error', reject) clearTimeout(timer)
} catch (error) { resolve()
zipStream.end() })
reject(error) .on('error', (error: Error) => {
} finally { core.warning(`zip stream: Artifact download failed: ${error.message}`)
clearTimeout(timer) reject(error)
} })
}) })
} }
@ -193,6 +192,7 @@ export async function downloadArtifactInternal(
core.info(`Starting download of artifact to: ${downloadPath}`) core.info(`Starting download of artifact to: ${downloadPath}`)
await streamExtract(signedUrl, downloadPath) await streamExtract(signedUrl, downloadPath)
core.info(`Artifact download completed successfully.`) core.info(`Artifact download completed successfully.`)
process.exit(0)
} catch (error) { } catch (error) {
throw new Error(`Unable to download and extract artifact: ${error.message}`) throw new Error(`Unable to download and extract artifact: ${error.message}`)
} }