From 60f54bf9940fbad0da145c920f3ce2640193aa51 Mon Sep 17 00:00:00 2001 From: Matias Date: Sat, 22 Jun 2019 19:25:26 -0300 Subject: [PATCH] Superalgos node v1 --- IndicatorBotProcessMainLoop.js | 5 ++-- Integrations/FileStorage.js | 46 +++++++++++++--------------------- Integrations/Strategy.js | 4 +-- MultiPeriodDaily.js | 8 +++--- MultiPeriodMarket.js | 5 +++- Run.js | 3 --- SensorBotProcessMainLoop.js | 2 +- StatusReport.js | 4 +-- docker-compose.yml | 2 +- package.json | 2 +- 10 files changed, 34 insertions(+), 47 deletions(-) diff --git a/IndicatorBotProcessMainLoop.js b/IndicatorBotProcessMainLoop.js index 24157ec81..feedc0ae7 100644 --- a/IndicatorBotProcessMainLoop.js +++ b/IndicatorBotProcessMainLoop.js @@ -11,6 +11,7 @@ const MULTI_PERIOD_MARKET = require(ROOT_DIR + 'MultiPeriodMarket'); const MULTI_PERIOD_DAILY = require(ROOT_DIR + 'MultiPeriodDaily'); const FILE_STORAGE = require('./Integrations/FileStorage.js'); + let fileStorage = FILE_STORAGE.newFileStorage(); 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. @@ -38,8 +39,6 @@ UI_COMMANDS = pUI_COMMANDS; processConfig = pProcessConfig; - let fileStorage = FILE_STORAGE.newFileStorage(); - let filePath; if (global.RUN_AS_TEAM) { @@ -339,7 +338,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES); + usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage); usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); diff --git a/Integrations/FileStorage.js b/Integrations/FileStorage.js index b7cd67f63..653f53e1c 100644 --- a/Integrations/FileStorage.js +++ b/Integrations/FileStorage.js @@ -13,10 +13,10 @@ exports.newFileStorage = function newFileStorage() { function getTextFile(container, filePath, callBackFunction) { try { - if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Entering function: ' + filePath) } + if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Entering function: '+ container.toLowerCase() + '/' + filePath) } axios({ - url: process.env.HOST_URL + 'graphql', + url: process.env.GATEWAY_ENDPOINT_K8S, method: 'post', data: { query: ` @@ -46,13 +46,16 @@ exports.newFileStorage = function newFileStorage() { callBackFunction(global.DEFAULT_OK_RESPONSE, response) else callBackFunction(global.CUSTOM_FAIL_RESPONSE) + }).catch(error => { if (ERROR_LOG === true) { console.log('newFileStorage: [ERROR] getTextFile -> Invalid JSON received. ') } - if (ERROR_LOG === true) { console.log('newFileStorage: [ERROR] getTextFile -> response.text = ' + error.message) } + if (ERROR_LOG === true) { console.log('newFileStorage: [ERROR] getTextFile -> error = ', error) } callBackFunction(global.DEFAULT_FAIL_RESPONSE) }) } catch (err) { - if (ERROR_LOG === true) { console.log('[ERROR] getTextFile -> err = ' + err.stack) } + if (ERROR_LOG === true) { console.log('[ERROR] getTextFile -> err = ', err) } + if (ERROR_LOG === true) { console.log('[ERROR] getTextFile -> stack = ', err.stack) } + callBackFunction(global.DEFAULT_FAIL_RESPONSE) } } @@ -61,7 +64,7 @@ exports.newFileStorage = function newFileStorage() { if (INFO_LOG === true) { console.log('[INFO] createTextFile -> Entering function: ' + filePath) } let response = await axios({ - url: process.env.HOST_URL + 'graphql', + url: process.env.GATEWAY_ENDPOINT_K8S, method: 'post', data: { query: ` @@ -73,38 +76,23 @@ exports.newFileStorage = function newFileStorage() { file: { container: container.toLowerCase(), filePath, - storage: process.env.HOST_STORAGE, - accessKey: process.env.HOST_ACCESS_KEY, + storage: 'localStorage', + accessKey: '', //TODO Pending fileContent } } } }) - if(!response){ - console.log('[ERROR] createTextFile -> err = ') - } + if (!response || response.data.errors) + callBackFunction(global.CUSTOM_FAIL_RESPONSE) + else + callBackFunction(global.DEFAULT_OK_RESPONSE) - // .then(res => { - // if (res.data.errors) { - // let error = { - // code: res.data.errors[0] - // } - // callBackFunction(error) - // return - // } - // let response = res.data.data.web_CreateFile - // if (response) - // callBackFunction(global.DEFAULT_OK_RESPONSE) - // else - // callBackFunction(global.CUSTOM_FAIL_RESPONSE) - // }).catch(error => { - // if (ERROR_LOG === true) { console.log('newFileStorage: [ERROR] createTextFile -> Invalid JSON received. ') } - // if (ERROR_LOG === true) { console.log('newFileStorage: [ERROR] createTextFile -> response.text = ' + error.message) } - // callBackFunction(global.DEFAULT_FAIL_RESPONSE) - // }) } catch (err) { - if (ERROR_LOG === true) { console.log('[ERROR] createTextFile -> err = ' + err.stack) } + if (ERROR_LOG === true) { console.log('[ERROR] createTextFile -> err = ', err.stack) } + if (ERROR_LOG === true) { console.log('[ERROR] createTextFile -> stack = ', err.stack) } + callBackFunction(global.DEFAULT_FAIL_RESPONSE) } } diff --git a/Integrations/Strategy.js b/Integrations/Strategy.js index 3ccdc5967..a26daefe3 100644 --- a/Integrations/Strategy.js +++ b/Integrations/Strategy.js @@ -15,7 +15,7 @@ exports.getStrategy = async function () { } const strategizerResponse = await axios({ - url: process.env.STRATEGIZER_ENDPOINT || process.env.GATEWAY_ENDPOINT, + url: process.env.STRATEGIZER_ENDPOINT || process.env.GATEWAY_ENDPOINT_K8S, method: 'post', data: { query: ` @@ -42,6 +42,6 @@ exports.getStrategy = async function () { return global.STRATEGY } catch (error) { - throw new Error('There has been an error getting the strategy: ' + error) + throw new Error('There has been an error getting the strategy: ', error) } } diff --git a/MultiPeriodDaily.js b/MultiPeriodDaily.js index 08cae3da7..526867dfe 100644 --- a/MultiPeriodDaily.js +++ b/MultiPeriodDaily.js @@ -58,7 +58,7 @@ } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES); + usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage); usertBot.initialize(dataDependencies, callBackFunction); } catch (err) { @@ -421,7 +421,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> Entering function."); } if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getPreviousFile -> onFileReceived -> text = " + text); } - if (err.message === "File does not exist." && botNeverRan === true) { + if ((err.message === "File does not exist." && botNeverRan === true) || err.code === 'The specified key does not exist.') { /* Sometimes one of the dependencies of an indicator for some reasons are not calculated from the begining of the market. @@ -436,7 +436,7 @@ return; } - if (err.result === "Fail Because" && err.message === "File does not exist.") { + if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); @@ -490,7 +490,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> Entering function."); } if (LOG_FILE_CONTENT === true) { logger.write(MODULE_NAME, "[INFO] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> text = " + text); } - if (err.result === "Fail Because" && err.message === "File does not exist.") { + if ((err.result === "Fail Because" && err.message === "File does not exist.") || err.code === 'The specified key does not exist.') { logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> err = " + err.message); logger.write(MODULE_NAME, "[ERROR] start -> processTimePeriods -> periodsLoopBody -> dependencyLoopBody -> getCurrentFile -> onFileReceived -> filePath = " + filePath); diff --git a/MultiPeriodMarket.js b/MultiPeriodMarket.js index fdd08f1d5..12e05a729 100644 --- a/MultiPeriodMarket.js +++ b/MultiPeriodMarket.js @@ -16,6 +16,9 @@ let usertBot; + const FILE_STORAGE = require('./Integrations/FileStorage.js'); + let fileStorage = FILE_STORAGE.newFileStorage(); + let processConfig; return thisObject; @@ -51,7 +54,7 @@ } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES); + usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage); usertBot.initialize(dataDependencies, callBackFunction); } catch (err) { diff --git a/Run.js b/Run.js index c8003e294..fa0580f06 100644 --- a/Run.js +++ b/Run.js @@ -35,9 +35,6 @@ function readExecutionConfiguration() { console.log("[INFO] Run -> readExecutionConfiguration -> Entering function. "); let startMode - // Environment Configuration - global.GATEWAY_ENDPOINT = process.env.GATEWAY_ENDPOINT - // General Financial Being Configuration global.DEV_TEAM = process.env.DEV_TEAM global.CURRENT_BOT_REPO = process.env.BOT + "-" + process.env.TYPE + "-Bot" diff --git a/SensorBotProcessMainLoop.js b/SensorBotProcessMainLoop.js index 610165797..26b49627c 100644 --- a/SensorBotProcessMainLoop.js +++ b/SensorBotProcessMainLoop.js @@ -303,7 +303,7 @@ if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] run -> loop -> initializeUserBot -> Entering function."); } - usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, STATUS_REPORT, exchangeAPI); + usertBot = USER_BOT_MODULE.newUserBot(bot, logger, COMMONS_MODULE, UTILITIES, fileStorage, STATUS_REPORT, exchangeAPI); usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); diff --git a/StatusReport.js b/StatusReport.js index b731f4a60..d1c583b4c 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -91,7 +91,7 @@ filePath += '/' + fileName - fileStorage.getTextFile(global.DEV_TEAM, filePath, onFileReceived); + fileStorage.getTextFile(owner.devTeam, filePath, onFileReceived); function onFileReceived(err, text) { @@ -187,7 +187,7 @@ let fileContent = JSON.stringify(thisObject.file); - fileStorage.createTextFile(global.DEV_TEAM, filePath, fileContent + '\n', onFileCreated); + fileStorage.createTextFile(owner.devTeam, filePath, fileContent + '\n', onFileCreated); function onFileCreated(err) { diff --git a/docker-compose.yml b/docker-compose.yml index 8ac5cc350..2d65a2cb5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: node: - image: superalgos/clone-executor:1.0.12 + image: superalgos/clone-executor:1.0.25 build: context: . dockerfile: ./Dockerfile diff --git a/package.json b/package.json index 6cf6f0627..d6db2b47b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@superalgos/clone-executor", - "version": "1.0.12", + "version": "1.0.25", "description": "Module responsible for executing the bots on the cloud.", "author": "Superalgos, ltd.", "license": "Apache-2.0",