diff --git a/lib/agent/index.js b/lib/agent/index.js index c363a4a59..6af9109d1 100644 --- a/lib/agent/index.js +++ b/lib/agent/index.js @@ -15,6 +15,9 @@ const { restore } = require('./utils/storage/restore'); const logo = require('./utils/logo'); const controlPanel = require('./control-panel'); +let timerForDataPreyConf; +let timerForDataPreyConfThirty; + const { // eslint-disable-next-line camelcase system, logger, program, exceptions, os_name, os_release, @@ -165,11 +168,16 @@ const actionForDataWithoutVerification = (errReadWithoutVerification, data) => { const correctDataTimedOut = () => correctPreyConf(config.all(), () => {}); +const setTimeCorrectData = () => { + if (timerForDataPreyConfThirty) clearInterval(timerForDataPreyConfThirty); + setTimeout(correctDataTimedOut, 1000 * 60 * 5); + timerForDataPreyConfThirty = setInterval(correctDataTimedOut, 1000 * 60 * 30); +}; + const preyConfReconf = () => { getDataFromShouldPreyCFile((_err, shouldPreyCFile) => { if (shouldPreyCFile && shouldPreyCFile.localeCompare('true') === 0) { - setTimeout(correctDataTimedOut, 1000 * 60 * 5); - setInterval(correctDataTimedOut, 1000 * 60 * 30); + setTimeCorrectData(); } else { // eslint-disable-next-line consistent-return getDataDb('preyconf', (_errorGetData, dataFromDb) => { @@ -178,7 +186,7 @@ const preyConfReconf = () => { if (preyConfData['control-panel.device_key'] && preyConfData['control-panel.api_key']) { return getDataFromShouldPreyCFile(reactToDataFromShouldPreyCFile); } - setInterval(() => { + timerForDataPreyConf = setInterval(() => { getDataFromShouldPreyCFile((errGetShould, dataShould) => { getDataDb('preyconf', (errorGetData, dataFromDbInside) => { if (errorGetData) return; @@ -192,7 +200,9 @@ const preyConfReconf = () => { } }); if (errGetShould) return; - if (dataShould && dataShould.localeCompare('true') === 0) { + if (shouldPreyCFile && shouldPreyCFile.localeCompare('true') === 0) { + setTimeCorrectData(); + clearInterval(timerForDataPreyConf); return; } readWithoutVerification(actionForDataWithoutVerification);