From c262ac0154d56cf1469a3fd6250544fb2fdd6c72 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Mon, 6 Jan 2020 14:06:24 -0500 Subject: [PATCH] Fix number parsing issues --- src/cacheHttpClient.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index 89bca63..97c9672 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -191,6 +191,14 @@ async function uploadChunk( ); } +function parseEnvNumber(key: string): number | undefined { + const value = Number(process.env[key]); + if (Number.isNaN(value) || value < 0) { + return undefined; + } + return value; +} + async function uploadFile( restClient: RestClient, cacheId: number, @@ -201,9 +209,9 @@ async function uploadFile( const resourceUrl = getCacheApiUrl() + "caches/" + cacheId.toString(); const fd = fs.openSync(archivePath, "r"); - const concurrency = Number(process.env["CACHE_UPLOAD_CONCURRENCY"]) ?? 4; // # of HTTP requests in parallel + const concurrency = parseEnvNumber("CACHE_UPLOAD_CONCURRENCY") ?? 4; // # of HTTP requests in parallel const MAX_CHUNK_SIZE = - Number(process.env["CACHE_UPLOAD_CHUNK_SIZE"]) ?? 32 * 1024 * 1024; // 32 MB Chunks + parseEnvNumber("CACHE_UPLOAD_CHUNK_SIZE") ?? 32 * 1024 * 1024; // 32 MB Chunks core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`); const parallelUploads = [...new Array(concurrency).keys()];