diff --git a/DebugLog.js b/DebugLog.js index 30e133cc9..6466bc986 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -86,8 +86,8 @@ return; } - blobContent = ""; - thisObject = {}; + //blobContent = ""; + //thisObject = {}; } } diff --git a/ExtractionBotProcessMainLoop.js b/ExtractionBotProcessMainLoop.js index 7ba6999af..d05a8a226 100644 --- a/ExtractionBotProcessMainLoop.js +++ b/ExtractionBotProcessMainLoop.js @@ -10,6 +10,10 @@ const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage'); + const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); + let logger; // We need this here in order for the loopHealth function to work and be able to rescue the loop when it gets in trouble. + let timeoutHandle; + let thisObject = { initialize: initialize, run: run @@ -145,9 +149,6 @@ /* For each loop we want to create a new log file. */ - const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); - let logger; - logger = DEBUG_MODULE.newDebugLog(); logger.bot = bot; logger.initialize(); @@ -469,7 +470,7 @@ } else { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } setTimeout(checkLoopHealth, processConfig.normalWaitTime * 5, bot.loopCounter); - setTimeout(loop, processConfig.normalWaitTime); + timeoutHandle = setTimeout(loop, processConfig.normalWaitTime); logger.persist(); } } @@ -477,7 +478,7 @@ case 'Retry': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } setTimeout(checkLoopHealth, processConfig.retryWaitTime * 5, bot.loopCounter); - setTimeout(loop, processConfig.retryWaitTime); + timeoutHandle = setTimeout(loop, processConfig.retryWaitTime); logger.persist(); } break; @@ -488,7 +489,7 @@ return; } else { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); } - setTimeout(loop, processConfig.sleepWaitTime); + timeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); logger.persist(); } } @@ -500,7 +501,7 @@ return; } else { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); } - setTimeout(loop, processConfig.comaWaitTime); + timeoutHandle = setTimeout(loop, processConfig.comaWaitTime); logger.persist(); } } @@ -518,6 +519,7 @@ console.log((new Date().toISOString() + " " + bot.codeName + " " + bot.process + " Loop # " + Number(bot.loopCounter) + " found dead. Resurrecting it now.")); logger.persist(); // We persist the logs of the failed execution. + clearTimeout(timeoutHandle); // We cancel the timeout in case the original loop was still running and schedulled to reexecute. loop(); // We restart the loop so that the processing can continue. } diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index f68e7e1f5..5340faded 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -10,6 +10,10 @@ const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage'); + const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); + let logger; // We need this here in order for the loopHealth function to work and be able to rescue the loop when it gets in trouble. + let timeoutHandle; + let thisObject = { initialize: initialize, run: run @@ -146,9 +150,6 @@ /* For each loop we want to create a new log file. */ - const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); - let logger; - logger = DEBUG_MODULE.newDebugLog(); logger.bot = bot; logger.initialize(); @@ -445,26 +446,26 @@ case 'Normal': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } setTimeout(checkLoopHealth, processConfig.normalWaitTime * 5, bot.loopCounter); - setTimeout(loop, processConfig.normalWaitTime); + timeoutHandle = setTimeout(loop, processConfig.normalWaitTime); logger.persist(); } break; case 'Retry': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } setTimeout(checkLoopHealth, processConfig.retryWaitTime * 5, bot.loopCounter); - setTimeout(loop, processConfig.retryWaitTime); + timeoutHandle = setTimeout(loop, processConfig.retryWaitTime); logger.persist(); } break; case 'Sleep': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); } - setTimeout(loop, processConfig.sleepWaitTime); + timeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); logger.persist(); } break; case 'Coma': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); } - setTimeout(loop, processConfig.comaWaitTime); + timeoutHandle = setTimeout(loop, processConfig.comaWaitTime); logger.persist(); } break; @@ -481,6 +482,7 @@ console.log((new Date().toISOString() + " " + bot.codeName + " " + bot.process + " Loop # " + Number(bot.loopCounter) + " found dead. Resurrecting it now.")); logger.persist(); // We persist the logs of the failed execution. + clearTimeout(timeoutHandle); // We cancel the timeout in case the original loop was still running and schedulled to reexecute. loop(); // We restart the loop so that the processing can continue. } diff --git a/TradingBotProcessMainLoop.js b/TradingBotProcessMainLoop.js index d63b65629..7541ceb4b 100644 --- a/TradingBotProcessMainLoop.js +++ b/TradingBotProcessMainLoop.js @@ -10,6 +10,10 @@ const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage'); + const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); + let logger; // We need this here in order for the loopHealth function to work and be able to rescue the loop when it gets in trouble. + let timeoutHandle; + let thisObject = { initialize: initialize, run: run @@ -146,9 +150,6 @@ /* For each loop we want to create a new log file. */ - const DEBUG_MODULE = require(ROOT_DIR + 'DebugLog'); - let logger; - logger = DEBUG_MODULE.newDebugLog(); logger.bot = bot; logger.initialize(); @@ -836,26 +837,26 @@ case 'Normal': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Normal -> Restarting Loop in " + (processConfig.normalWaitTime / 1000) + " seconds."); } setTimeout(checkLoopHealth, processConfig.normalWaitTime * 5, bot.loopCounter); - setTimeout(loop, processConfig.normalWaitTime); + timeoutHandle = setTimeout(loop, processConfig.normalWaitTime); logger.persist(); } break; case 'Retry': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Retry -> Restarting Loop in " + (processConfig.retryWaitTime / 1000) + " seconds."); } setTimeout(checkLoopHealth, processConfig.retryWaitTime * 5, bot.loopCounter); - setTimeout(loop, processConfig.retryWaitTime); + timeoutHandle = setTimeout(loop, processConfig.retryWaitTime); logger.persist(); } break; case 'Sleep': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Sleep -> Restarting Loop in " + (processConfig.sleepWaitTime / 60000) + " minutes."); } - setTimeout(loop, processConfig.sleepWaitTime); + timeoutHandle = setTimeout(loop, processConfig.sleepWaitTime); logger.persist(); } break; case 'Coma': { if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> loopControl -> Coma -> Restarting Loop in " + (processConfig.comaWaitTime / 3600000) + " hours."); } - setTimeout(loop, processConfig.comaWaitTime); + timeoutHandle = setTimeout(loop, processConfig.comaWaitTime); logger.persist(); } break; @@ -869,9 +870,10 @@ logger.write(MODULE_NAME, "[ERROR] run -> loop -> checkLoopHealth -> Dying loop found."); logger.write(MODULE_NAME, "[ERROR] run -> loop -> checkLoopHealth -> pLastLoop = " + pLastLoop); - console.log((new Date().toISOString() + " " + bot.codeName + " " + bot.process + " Loop # " + Number(bot.loopCounter) + " found dead. Resurrecting it now." )); + console.log((new Date().toISOString() + " " + bot.codeName + " " + bot.process + " Loop # " + Number(bot.loopCounter) + " found dead. Resurrecting it now.")); logger.persist(); // We persist the logs of the failed execution. + clearTimeout(timeoutHandle); // We cancel the timeout in case the original loop was still running and schedulled to reexecute. loop(); // We restart the loop so that the processing can continue. }