mirror of https://github.com/actions/toolkit
moving timer outside of uploadZipToBlobStorage
parent
90fca23920
commit
425f05e29d
|
@ -25,6 +25,15 @@ export async function uploadZipToBlobStorage(
|
||||||
): Promise<BlobUploadResponse> {
|
): Promise<BlobUploadResponse> {
|
||||||
let uploadByteCount = 0
|
let uploadByteCount = 0
|
||||||
let lastProgressTime = Date.now()
|
let lastProgressTime = Date.now()
|
||||||
|
const chunkTimer = (timeout: number): NodeJS.Timeout =>
|
||||||
|
setTimeout(() => {
|
||||||
|
const now = Date.now()
|
||||||
|
// if there's been more than 30 seconds since the
|
||||||
|
// last progress event, then we'll consider the upload stalled
|
||||||
|
if (now - lastProgressTime > timeout) {
|
||||||
|
throw new Error('Upload progress stalled.')
|
||||||
|
}
|
||||||
|
}, timeout)
|
||||||
|
|
||||||
const maxConcurrency = getConcurrency()
|
const maxConcurrency = getConcurrency()
|
||||||
const bufferSize = getUploadChunkSize()
|
const bufferSize = getUploadChunkSize()
|
||||||
|
@ -39,21 +48,12 @@ export async function uploadZipToBlobStorage(
|
||||||
const uploadCallback = (progress: TransferProgressEvent): void => {
|
const uploadCallback = (progress: TransferProgressEvent): void => {
|
||||||
core.info(`Uploaded bytes ${progress.loadedBytes}`)
|
core.info(`Uploaded bytes ${progress.loadedBytes}`)
|
||||||
uploadByteCount = progress.loadedBytes
|
uploadByteCount = progress.loadedBytes
|
||||||
progressTimeout(timeoutDuration)
|
chunkTimer(timeoutDuration)
|
||||||
|
lastProgressTime = Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout if the upload stalls
|
// // Timeout if the upload stalls
|
||||||
const progressTimeout = (timeout: number): NodeJS.Timeout =>
|
// const progressTimeout
|
||||||
setTimeout(() => {
|
|
||||||
const now = Date.now()
|
|
||||||
// if there's been more than 30 seconds since the
|
|
||||||
// last progress event, then we'll consider the upload stalled
|
|
||||||
if (now - lastProgressTime > timeout) {
|
|
||||||
throw new Error('Upload progress stalled.')
|
|
||||||
}
|
|
||||||
}, timeout)
|
|
||||||
|
|
||||||
lastProgressTime = Date.now()
|
|
||||||
const options: BlockBlobUploadStreamOptions = {
|
const options: BlockBlobUploadStreamOptions = {
|
||||||
blobHTTPHeaders: {blobContentType: 'zip'},
|
blobHTTPHeaders: {blobContentType: 'zip'},
|
||||||
onProgress: uploadCallback
|
onProgress: uploadCallback
|
||||||
|
@ -96,7 +96,7 @@ export async function uploadZipToBlobStorage(
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the progress timeout when upload completes
|
// clear the progress timeout when upload completes
|
||||||
clearTimeout(progressTimeout(timeoutDuration))
|
clearTimeout(chunkTimer(timeoutDuration))
|
||||||
return {
|
return {
|
||||||
uploadSize: uploadByteCount,
|
uploadSize: uploadByteCount,
|
||||||
sha256Hash
|
sha256Hash
|
||||||
|
|
Loading…
Reference in New Issue