Skip to content

Commit

Permalink
[Artifacts] More detailed information for chunked uploads (actions#957)
Browse files Browse the repository at this point in the history
* More detailed information for chunked uploads

* Run npm format
  • Loading branch information
konradpabjan authored Dec 6, 2021
1 parent 3997079 commit 0546c07
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 40 deletions.
35 changes: 10 additions & 25 deletions src/internal/status-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ export class StatusReporter {
private displayFrequencyInMilliseconds: number
private largeFiles = new Map<string, string>()
private totalFileStatus: NodeJS.Timeout | undefined
private largeFileStatus: NodeJS.Timeout | undefined

constructor(displayFrequencyInMilliseconds: number) {
this.totalFileStatus = undefined
this.largeFileStatus = undefined
this.displayFrequencyInMilliseconds = displayFrequencyInMilliseconds
}

Expand All @@ -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 {
Expand Down
31 changes: 16 additions & 15 deletions src/internal/upload-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
)
}
}
}

Expand Down

0 comments on commit 0546c07

Please sign in to comment.