From 637dd083889e85f78b3d7a73c699a6252ce79600 Mon Sep 17 00:00:00 2001 From: Shweta Jain Date: Fri, 25 Aug 2017 18:00:48 +0530 Subject: [PATCH] clear all open intervals if not needed --- lib/loggly/common.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/loggly/common.js b/lib/loggly/common.js index 18ad759..1dc8de2 100644 --- a/lib/loggly/common.js +++ b/lib/loggly/common.js @@ -206,11 +206,12 @@ common.loggly = function () { if (timerFunction === null) { timerFunction = setInterval(function () { sendBulkLogs(); + if (timerFunction && !arrMsg.length) { + clearInterval(timerFunction) + timerFunction = null; + } },5000); - } else if (timerFunction && !arrMsg.length) { - clearInterval(timerFunction); - timerFunction = null; - } + } arrMsg.push(requestBody); if (arrMsg.length === arrSize) { sendBulkLogs(); @@ -226,11 +227,12 @@ common.loggly = function () { if (timerFunctionForBufferedLogs === null) { timerFunctionForBufferedLogs = setInterval(function () { if (arrBufferedMsg.length) sendBufferdLogstoLoggly(); + if (timerFunctionForBufferedLogs && !arrBufferedMsg.length) { + clearInterval(timerFunctionForBufferedLogs); + timerFunctionForBufferedLogs = null; + } }, bufferOptions.retriesInMilliSeconds); - } else if (timerFunctionForBufferedLogs && !arrBufferedMsg.length) { - clearInterval(timerFunctionForBufferedLogs); - timerFunctionForBufferedLogs = null; - } + } function sendBufferdLogstoLoggly() {