diff --git a/.vs/AACloudPlatform/v15/.suo b/.vs/AACloudPlatform/v15/.suo index 049d242be..88ddd4ad7 100644 Binary files a/.vs/AACloudPlatform/v15/.suo and b/.vs/AACloudPlatform/v15/.suo differ diff --git a/Context.js b/Context.js index 5705fcd62..fd13398b9 100644 --- a/Context.js +++ b/Context.js @@ -1,4 +1,4 @@ -exports.newContext = function newContext(BOT, DEBUG_MODULE, FILE_STORAGE) { +exports.newContext = function newContext(BOT, DEBUG_MODULE, FILE_STORAGE, UTILITIES) { const FULL_LOG = true; @@ -60,6 +60,10 @@ logger.fileName = MODULE_NAME; logger.bot = bot; + /* Utilities needed. */ + + let utilities = UTILITIES.newUtilities(bot); + /* Storage account to be used here. */ let cloudStorage = FILE_STORAGE.newAzureFileStorage(bot); diff --git a/Datasource.js b/Datasource.js index 4f2c9b90e..2b1d598f3 100644 --- a/Datasource.js +++ b/Datasource.js @@ -1,4 +1,4 @@ -exports.newDatasource = function newDatasource(BOT, DEBUG_MODULE, FILE_STORAGE) { +exports.newDatasource = function newDatasource(BOT, DEBUG_MODULE, FILE_STORAGE, UTILITIES) { const FULL_LOG = true; @@ -56,6 +56,10 @@ let oliviaAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); let tomAzureFileStorage = FILE_STORAGE.newAzureFileStorage(bot); + /* Utilities needed. */ + + let utilities = UTILITIES.newUtilities(bot); + return thisObject; function initialize(callBackFunction) { diff --git a/Trading Bot Main Loop.js b/Trading Bot Main Loop.js index 223374b7b..eb9d0fd1a 100644 --- a/Trading Bot Main Loop.js +++ b/Trading Bot Main Loop.js @@ -82,7 +82,7 @@ if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); } - context = CONTEXT.newContext(bot, DEBUG_MODULE, AZURE_FILE_STORAGE); + context = CONTEXT.newContext(bot, DEBUG_MODULE, AZURE_FILE_STORAGE, UTILITIES); context.initialize(onInizialized); function onInizialized(err) { @@ -115,7 +115,7 @@ if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDatasource -> Entering function."); } - datasource = DATASOURCE.newDatasource(bot, DEBUG_MODULE, AZURE_FILE_STORAGE); + datasource = DATASOURCE.newDatasource(bot, DEBUG_MODULE, AZURE_FILE_STORAGE, UTILITIES); datasource.initialize(onInizialized); function onInizialized(err) { @@ -186,11 +186,26 @@ function onInizialized(err) { - if (err.result === global.DEFAULT_OK_RESPONSE.result) { - initializeUserBot(); - } else { - logger.write("[ERROR] run -> loop -> initializeAssistant -> err = " + err.message); - callBackFunction(err); + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeAssistant -> onInizialized > Execution finished well. :-)"); + initializeUserBot(); + return; + } + break; + case global.DEFAULT_RETRY_RESPONSE.result: { // Something bad happened, but if we retry in a while it might go through the next time. + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + break; + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeAssistant -> onInizialized > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + break; } } }