upgrading archiver package along with chunk timeout

This commit is contained in:
Vallie Joseph
2024-04-09 18:02:48 +00:00
parent 9ddf153e00
commit 2e7a11c409
5 changed files with 642 additions and 527 deletions

View File

@@ -24,11 +24,13 @@ export async function uploadZipToBlobStorage(
zipUploadStream: ZipUploadStream
): Promise<BlobUploadResponse> {
let uploadByteCount = 0
const lastProgressTime = Date.now()
const maxConcurrency = getConcurrency()
const bufferSize = getUploadChunkSize()
const blobClient = new BlobClient(authenticatedUploadURL)
const blockBlobClient = blobClient.getBlockBlobClient()
const timeoutDuration = 300000 // 30 seconds
core.debug(
`Uploading artifact zip to blob storage with maxConcurrency: ${maxConcurrency}, bufferSize: ${bufferSize}`
@@ -37,8 +39,19 @@ export async function uploadZipToBlobStorage(
const uploadCallback = (progress: TransferProgressEvent): void => {
core.info(`Uploaded bytes ${progress.loadedBytes}`)
uploadByteCount = progress.loadedBytes
progressTimeout(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)
const options: BlockBlobUploadStreamOptions = {
blobHTTPHeaders: {blobContentType: 'zip'},
onProgress: uploadCallback
@@ -80,6 +93,8 @@ export async function uploadZipToBlobStorage(
)
}
// clear the progress timeout when upload completes
clearTimeout(progressTimeout(timeoutDuration))
return {
uploadSize: uploadByteCount,
sha256Hash