From 010fa2ca8390d102ceaf57dd3b0ec73f4e1f480a Mon Sep 17 00:00:00 2001 From: Piotr Grzesik Date: Thu, 15 Apr 2021 12:45:09 +0200 Subject: [PATCH] feat: Remove `ongoingRequestCount` counter --- lib/utils/analytics/index.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/utils/analytics/index.js b/lib/utils/analytics/index.js index fd6141bd4..716f502a4 100644 --- a/lib/utils/analytics/index.js +++ b/lib/utils/analytics/index.js @@ -18,9 +18,7 @@ const isUuid = RegExp.prototype.test.bind( /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/ ); -// TODO: CLEAN UP THESE let serverlessRunEndTime; -let ongoingRequestsCount = 0; const logError = (type, error) => { if (!process.env.SLS_STATS_DEBUG) return; @@ -37,12 +35,10 @@ const processResponseBody = async (response, ids, startTime) => { } catch (error) { logError(`Response processing error for ${ids || ''}`, error); return null; - } finally { - --ongoingRequestsCount; } const endTime = Date.now(); - if (serverlessRunEndTime && !ongoingRequestsCount && process.env.SLS_STATS_DEBUG) { + if (serverlessRunEndTime && process.env.SLS_STATS_DEBUG) { log( format( 'Stats request prevented process from exiting for %dms (request time: %dms)', @@ -55,7 +51,6 @@ const processResponseBody = async (response, ids, startTime) => { }; async function request(payload, { ids, timeout } = {}) { - ++ongoingRequestsCount; const startTime = Date.now(); let response; const body = JSON.stringify(payload); @@ -100,7 +95,7 @@ async function report(payload, options = {}) { if (!analyticsUrl) return null; const isForced = options && options.isForced; if (areAnalyticsDisabled && !isForced) return null; - if (!cacheDirPath) return request(payload); + if (!cacheDirPath) return request([payload]); const id = uuid(); const [, requestResult] = await Promise.all([ @@ -140,8 +135,6 @@ async function sendPending(options = {}) { process.nextTick(markServerlessRunEnd); - // TODO: TESTS - // TODO: CHANGE NAME const payloadsWithIds = ( await Promise.all( dirFilenames.map(async (dirFilename) => {