mirror of https://github.com/actions/toolkit
[Artifacts] More detailed information for chunked uploads (#957)
* More detailed information for chunked uploads * Run npm formatpull/960/head
parent
cdd4e107a6
commit
45a3c7bf81
|
@ -14,11 +14,9 @@ export class StatusReporter {
|
||||||
private displayFrequencyInMilliseconds: number
|
private displayFrequencyInMilliseconds: number
|
||||||
private largeFiles = new Map<string, string>()
|
private largeFiles = new Map<string, string>()
|
||||||
private totalFileStatus: NodeJS.Timeout | undefined
|
private totalFileStatus: NodeJS.Timeout | undefined
|
||||||
private largeFileStatus: NodeJS.Timeout | undefined
|
|
||||||
|
|
||||||
constructor(displayFrequencyInMilliseconds: number) {
|
constructor(displayFrequencyInMilliseconds: number) {
|
||||||
this.totalFileStatus = undefined
|
this.totalFileStatus = undefined
|
||||||
this.largeFileStatus = undefined
|
|
||||||
this.displayFrequencyInMilliseconds = displayFrequencyInMilliseconds
|
this.displayFrequencyInMilliseconds = displayFrequencyInMilliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,42 +42,29 @@ export class StatusReporter {
|
||||||
)}%)`
|
)}%)`
|
||||||
)
|
)
|
||||||
}, this.displayFrequencyInMilliseconds)
|
}, 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
|
// 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(
|
updateLargeFileStatus(
|
||||||
fileName: string,
|
fileName: string,
|
||||||
numerator: number,
|
chunkStartIndex: number,
|
||||||
denominator: number
|
chunkEndIndex: number,
|
||||||
|
totalUploadFileSize: number
|
||||||
): void {
|
): void {
|
||||||
// display 1 decimal place without any rounding
|
// display 1 decimal place without any rounding
|
||||||
const percentage = this.formatPercentage(numerator, denominator)
|
const percentage = this.formatPercentage(chunkEndIndex, totalUploadFileSize)
|
||||||
const displayInformation = `Uploading ${fileName} (${percentage.slice(
|
info(
|
||||||
|
`Uploaded ${fileName} (${percentage.slice(
|
||||||
0,
|
0,
|
||||||
percentage.indexOf('.') + 2
|
percentage.indexOf('.') + 2
|
||||||
)}%)`
|
)}%) chunks ${chunkStartIndex}:${chunkEndIndex}`
|
||||||
|
)
|
||||||
// any previously added display information should be overwritten for the specific large file because a map is being used
|
|
||||||
this.largeFiles.set(fileName, displayInformation)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop(): void {
|
stop(): void {
|
||||||
if (this.totalFileStatus) {
|
if (this.totalFileStatus) {
|
||||||
clearInterval(this.totalFileStatus)
|
clearInterval(this.totalFileStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.largeFileStatus) {
|
|
||||||
clearInterval(this.largeFileStatus)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementProcessedCount(): void {
|
incrementProcessedCount(): void {
|
||||||
|
|
|
@ -327,17 +327,8 @@ export class UploadHttpClient {
|
||||||
parameters.maxChunkSize
|
parameters.maxChunkSize
|
||||||
)
|
)
|
||||||
|
|
||||||
// if an individual file is greater than 100MB (1024*1024*100) in size, display extra information about the upload status
|
const startChunkIndex = offset
|
||||||
if (uploadFileSize > 104857600) {
|
const endChunkIndex = offset + chunkSize - 1
|
||||||
this.statusReporter.updateLargeFileStatus(
|
|
||||||
parameters.file,
|
|
||||||
offset,
|
|
||||||
uploadFileSize
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const start = offset
|
|
||||||
const end = offset + chunkSize - 1
|
|
||||||
offset += parameters.maxChunkSize
|
offset += parameters.maxChunkSize
|
||||||
|
|
||||||
if (abortFileUpload) {
|
if (abortFileUpload) {
|
||||||
|
@ -351,12 +342,12 @@ export class UploadHttpClient {
|
||||||
parameters.resourceUrl,
|
parameters.resourceUrl,
|
||||||
() =>
|
() =>
|
||||||
fs.createReadStream(uploadFilePath, {
|
fs.createReadStream(uploadFilePath, {
|
||||||
start,
|
start: startChunkIndex,
|
||||||
end,
|
end: endChunkIndex,
|
||||||
autoClose: false
|
autoClose: false
|
||||||
}),
|
}),
|
||||||
start,
|
startChunkIndex,
|
||||||
end,
|
endChunkIndex,
|
||||||
uploadFileSize,
|
uploadFileSize,
|
||||||
isGzip,
|
isGzip,
|
||||||
totalFileSize
|
totalFileSize
|
||||||
|
@ -369,6 +360,16 @@ export class UploadHttpClient {
|
||||||
failedChunkSizes += chunkSize
|
failedChunkSizes += chunkSize
|
||||||
core.warning(`Aborting upload for ${parameters.file} due to failure`)
|
core.warning(`Aborting upload for ${parameters.file} due to failure`)
|
||||||
abortFileUpload = true
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue