From 45a3c7bf81b877f5bac5f7cbb36a975a9f382f43 Mon Sep 17 00:00:00 2001 From: Konrad Pabjan Date: Mon, 6 Dec 2021 16:48:14 -0500 Subject: [PATCH] [Artifacts] More detailed information for chunked uploads (#957) * More detailed information for chunked uploads * Run npm format --- .../artifact/src/internal/status-reporter.ts | 35 ++++++------------- .../src/internal/upload-http-client.ts | 31 ++++++++-------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/packages/artifact/src/internal/status-reporter.ts b/packages/artifact/src/internal/status-reporter.ts index ed14cfd4..ee87ce68 100644 --- a/packages/artifact/src/internal/status-reporter.ts +++ b/packages/artifact/src/internal/status-reporter.ts @@ -14,11 +14,9 @@ export class StatusReporter { private displayFrequencyInMilliseconds: number private largeFiles = new Map() private totalFileStatus: NodeJS.Timeout | undefined - private largeFileStatus: NodeJS.Timeout | undefined constructor(displayFrequencyInMilliseconds: number) { this.totalFileStatus = undefined - this.largeFileStatus = undefined this.displayFrequencyInMilliseconds = displayFrequencyInMilliseconds } @@ -44,42 +42,29 @@ export class StatusReporter { )}%)` ) }, this.displayFrequencyInMilliseconds) - - // displays extra information about any large files that take a significant amount of time to upload or download every 1 second - this.largeFileStatus = setInterval(() => { - for (const value of Array.from(this.largeFiles.values())) { - info(value) - } - // delete all entries in the map after displaying the information so it will not be displayed again unless explicitly added - this.largeFiles.clear() - }, 1000) } // if there is a large file that is being uploaded in chunks, this is used to display extra information about the status of the upload updateLargeFileStatus( fileName: string, - numerator: number, - denominator: number + chunkStartIndex: number, + chunkEndIndex: number, + totalUploadFileSize: number ): void { // display 1 decimal place without any rounding - const percentage = this.formatPercentage(numerator, denominator) - const displayInformation = `Uploading ${fileName} (${percentage.slice( - 0, - percentage.indexOf('.') + 2 - )}%)` - - // any previously added display information should be overwritten for the specific large file because a map is being used - this.largeFiles.set(fileName, displayInformation) + const percentage = this.formatPercentage(chunkEndIndex, totalUploadFileSize) + info( + `Uploaded ${fileName} (${percentage.slice( + 0, + percentage.indexOf('.') + 2 + )}%) chunks ${chunkStartIndex}:${chunkEndIndex}` + ) } stop(): void { if (this.totalFileStatus) { clearInterval(this.totalFileStatus) } - - if (this.largeFileStatus) { - clearInterval(this.largeFileStatus) - } } incrementProcessedCount(): void { diff --git a/packages/artifact/src/internal/upload-http-client.ts b/packages/artifact/src/internal/upload-http-client.ts index bf3d2b33..473f40d2 100644 --- a/packages/artifact/src/internal/upload-http-client.ts +++ b/packages/artifact/src/internal/upload-http-client.ts @@ -327,17 +327,8 @@ export class UploadHttpClient { parameters.maxChunkSize ) - // if an individual file is greater than 100MB (1024*1024*100) in size, display extra information about the upload status - if (uploadFileSize > 104857600) { - this.statusReporter.updateLargeFileStatus( - parameters.file, - offset, - uploadFileSize - ) - } - - const start = offset - const end = offset + chunkSize - 1 + const startChunkIndex = offset + const endChunkIndex = offset + chunkSize - 1 offset += parameters.maxChunkSize if (abortFileUpload) { @@ -351,12 +342,12 @@ export class UploadHttpClient { parameters.resourceUrl, () => fs.createReadStream(uploadFilePath, { - start, - end, + start: startChunkIndex, + end: endChunkIndex, autoClose: false }), - start, - end, + startChunkIndex, + endChunkIndex, uploadFileSize, isGzip, totalFileSize @@ -369,6 +360,16 @@ export class UploadHttpClient { failedChunkSizes += chunkSize core.warning(`Aborting upload for ${parameters.file} due to failure`) abortFileUpload = true + } else { + // if an individual file is greater than 8MB (1024*1024*8) in size, display extra information about the upload status + if (uploadFileSize > 8388608) { + this.statusReporter.updateLargeFileStatus( + parameters.file, + startChunkIndex, + endChunkIndex, + uploadFileSize + ) + } } }