1
0
Fork 0

moving timer outside of uploadZipToBlobStorage

pull/1712/head
Vallie Joseph 2024-04-09 21:04:29 +00:00
parent 90fca23920
commit 425f05e29d
1 changed files with 14 additions and 14 deletions

View File

@ -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)
}
// Timeout if the upload stalls
const progressTimeout = (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)
lastProgressTime = Date.now() lastProgressTime = Date.now()
}
// // Timeout if the upload stalls
// const progressTimeout
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