From 425f05e29d8c6ebb68a53812af873f88c906bad0 Mon Sep 17 00:00:00 2001 From: Vallie Joseph Date: Tue, 9 Apr 2024 21:04:29 +0000 Subject: [PATCH] moving timer outside of uploadZipToBlobStorage --- .../src/internal/upload/blob-upload.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/artifact/src/internal/upload/blob-upload.ts b/packages/artifact/src/internal/upload/blob-upload.ts index 88ed54cd..f7c0fcf9 100644 --- a/packages/artifact/src/internal/upload/blob-upload.ts +++ b/packages/artifact/src/internal/upload/blob-upload.ts @@ -25,6 +25,15 @@ export async function uploadZipToBlobStorage( ): Promise { let uploadByteCount = 0 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 bufferSize = getUploadChunkSize() @@ -39,21 +48,12 @@ export async function uploadZipToBlobStorage( const uploadCallback = (progress: TransferProgressEvent): void => { core.info(`Uploaded bytes ${progress.loadedBytes}`) uploadByteCount = progress.loadedBytes - progressTimeout(timeoutDuration) + chunkTimer(timeoutDuration) + lastProgressTime = Date.now() } - // 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() + // // Timeout if the upload stalls + // const progressTimeout const options: BlockBlobUploadStreamOptions = { blobHTTPHeaders: {blobContentType: 'zip'}, onProgress: uploadCallback @@ -96,7 +96,7 @@ export async function uploadZipToBlobStorage( } // clear the progress timeout when upload completes - clearTimeout(progressTimeout(timeoutDuration)) + clearTimeout(chunkTimer(timeoutDuration)) return { uploadSize: uploadByteCount, sha256Hash