Compare commits

...

3 Commits

Author SHA1 Message Date
Sampark Sharma 14f28534ef
Stop progress bar on message.complete 2023-02-10 12:02:26 +00:00
Sampark Sharma ae026cf7c6
Fix bugs 2023-02-10 11:52:49 +00:00
Sampark Sharma 3d0da1ea1a
Add download progress for httpclient method 2023-02-10 11:34:10 +00:00
2 changed files with 27 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import * as util from 'util'
import * as utils from './cacheUtils'
import {SocketTimeout} from './constants'
import {DownloadOptions} from '../options'
import {retryHttpClientResponse} from './requestUtils'
import {retryHttpClientResponse, sleep} from './requestUtils'
import {AbortController} from '@azure/abort-controller'
@ -161,6 +161,28 @@ export class DownloadProgress {
}
}
async function displayDownloadProgress(message: any, startTime: number): Promise<void> {
const socket = message.socket
while(!message.complete) {
const byteRead = socket.bytesRead
const totalBytes = 100000
const percentage = (100 * (byteRead / totalBytes)).toFixed(
1
)
const elapsedTime = Date.now() - startTime
const downloadSpeed = (
byteRead /
(1024 * 1024) /
(elapsedTime / 1000)
).toFixed(1)
core.info(
`Received ${byteRead} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec`
)
sleep(100)
}
}
/**
* Download the cache using the Actions toolkit http-client
*
@ -171,6 +193,7 @@ export async function downloadCacheHttpClient(
archiveLocation: string,
archivePath: string
): Promise<void> {
const startTime = Date.now()
const writeStream = fs.createWriteStream(archivePath)
const httpClient = new HttpClient('actions/cache')
const downloadResponse = await retryHttpClientResponse(
@ -184,6 +207,8 @@ export async function downloadCacheHttpClient(
core.debug(`Aborting download, socket timed out after ${SocketTimeout} ms`)
})
await displayDownloadProgress(downloadResponse.message, startTime)
await pipeResponseToStream(downloadResponse, writeStream)
// Validate download size.

View File

@ -33,7 +33,7 @@ export function isRetryableStatusCode(statusCode?: number): boolean {
return retryableStatusCodes.includes(statusCode)
}
async function sleep(milliseconds: number): Promise<void> {
export async function sleep(milliseconds: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}