diff --git a/DataDependencies.js b/DataDependencies.js index 552f6a64f..54eb5916d 100644 --- a/DataDependencies.js +++ b/DataDependencies.js @@ -60,14 +60,27 @@ /* For each dependency declared at the nodeArray, we will initialize a DataSet as part of this initialization process. */ - let alreadyCalledBack = false; - let addCount = 0; + let alreadyCalledBack = false + let addCount = 0 + let skipCount = 0 + + /* + The current nodeArray that we have includes all the dependencies daclared in the Data Mine / Trading Mine + process dependencies, minus the ones without reference parent, meaning that references Data Mines that are + not present at the workspace. From all the remaining dependencies there will be others that we need to + filter out, and they are the ones which the user does not have a data product anywhere on the network where + this task is running, that is storing the data associated to this dependency. The way we use to filter this + out is by analizyng the response of the initialization call to the DataSet module. If it did not fail but + it was not initialized, then we will assume this happened because the data could not be located and we will + assume the user did this on purpose and we will filter out this dependency by not putting it on this new array. + */ + let newNodeArray = [] for (let i = 0; i < thisObject.nodeArray.length; i++) { let dataSetModule = DATA_SET.newDataSet(BOT, logger); dataSetModule.initialize(thisObject.nodeArray[i], onInitilized); - function onInitilized(err) { + function onInitilized(err, wasInitialized) { if (err.result !== global.DEFAULT_OK_RESPONSE.result) { logger.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> err = " + JSON.stringify(err)); @@ -76,17 +89,26 @@ callBackFunction(err); return; } - addDataSet(); + + if (wasInitialized === true) { + addCount++; + newNodeArray.push(thisObject.nodeArray[i]) + addDataSet() + } else { + skipCount++ + } + checkIfWeAreDone() } - function addDataSet() { - addCount++; - + function addDataSet() { thisObject.dataSetsModulesArray.push(dataSetModule); + } - if (addCount === thisObject.nodeArray.length) { + function checkIfWeAreDone() { + if (addCount + skipCount === thisObject.nodeArray.length) { if (alreadyCalledBack === false) { alreadyCalledBack = true + thisObject.nodeArray = newNodeArray callBackFunction(global.DEFAULT_OK_RESPONSE); return; } diff --git a/DataSet.js b/DataSet.js index 5d1527055..5b43b7bbf 100644 --- a/DataSet.js +++ b/DataSet.js @@ -83,10 +83,10 @@ exports.newDataSet = function newDataSet(BOT, logger) { let networkNode = global.FIND_NODE_IN_NODE_ARRAY(nodeArray, 'Network Node') if (networkNode === undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Network Node not found.") - logger.write(MODULE_NAME, "[ERROR] initialize -> Initialization Failed because we could not find where the data of this dataset is located within the network. Check the logs for more info."); - logger.write(MODULE_NAME, "[ERROR] initialize -> Could not find where " + datasetProductDefinition.name + " for " + bot.exchange + " " + bot.market.baseAsset + "/" + bot.market.quotedAsset + " is stored within the network."); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + logger.write(MODULE_NAME, "[WARN] initialize -> Network Node not found.") + logger.write(MODULE_NAME, "[WARN] initialize -> Initialization Failed because we could not find where the data of this dataset is located within the network. Check the logs for more info."); + logger.write(MODULE_NAME, "[WARN] initialize -> Could not find where " + datasetProductDefinition.name + " for " + bot.exchange + " " + bot.market.baseAsset + "/" + bot.market.quotedAsset + " is stored within the network."); + callBackFunction(global.DEFAULT_OK_RESPONSE, false); return } @@ -94,7 +94,7 @@ exports.newDataSet = function newDataSet(BOT, logger) { if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Retrieving data from " + networkNode.name + " -> host = " + networkNode.config.host + ' -> port = ' + networkNode.config.webPort + '.'); } fileStorage = FILE_STORAGE.newFileStorage(logger, networkNode.config.host, networkNode.config.webPort); - callBackFunction(global.DEFAULT_OK_RESPONSE); + callBackFunction(global.DEFAULT_OK_RESPONSE, true); } catch (err) { logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.stack);