Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14f28534ef | |||
| ae026cf7c6 | |||
| 3d0da1ea1a |
+26
-1
@@ -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.
|
||||
|
||||
+1
-1
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user