1
0
Fork 0

lint and format

pull/1613/head
bethanyj28 2023-12-21 09:25:34 -05:00
parent ecb4df89bf
commit ff2c524611
1 changed files with 18 additions and 10 deletions

View File

@ -17,7 +17,6 @@ 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)
@ -42,12 +41,14 @@ 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)
core.info(`Artifact downloaded successfully after ${retryCount} retries.`) core.info(`Artifact downloaded successfully after ${retryCount} retries.`)
return return
} catch (error) { } catch (error) {
retryCount++ retryCount++
core.warning(`Failed to download artifact after ${retryCount} retries due to ${error.message}. 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))
} }
@ -56,7 +57,10 @@ 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(url: string,directory: string): Promise<void> { async function streamExtractInternal(
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)
@ -71,17 +75,21 @@ async function streamExtractInternal(url: string,directory: string): Promise<voi
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const timerFn = (): void => { const timerFn = (): void => {
// close response stream // close response stream
core.warning("timerFn: closing response stream") core.warning('timerFn: closing response stream')
response.message.destroy(new Error(`Blob storage chunk did not respond in ${timeout}ms`)) response.message.destroy(
new Error(`Blob storage chunk did not respond in ${timeout}ms`)
)
} }
let timer = setTimeout(timerFn, timeout) const timer = setTimeout(timerFn, timeout)
response.message response.message
.on('data', () => { .on('data', () => {
timer.refresh() timer.refresh()
}) })
.on('error', (error: Error) => { .on('error', (error: Error) => {
core.warning(`response.message: Artifact download failed: ${error.message}`) core.warning(
`response.message: Artifact download failed: ${error.message}`
)
clearTimeout(timer) clearTimeout(timer)
reject(error) reject(error)
}) })