Bot Source Code read from Cloud
This commit is contained in:
1 parent
41c89d1b1d
commit
6ccac513b8
2 files changed
+83
-18
No files matched your search
@@ -180,21 +180,22 @@ exports.newRoot = function newRoot() {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log("[ERROR] Root -> start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message);
|
||||
callBack(err);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
botConfig = JSON.parse(text);
|
||||
botConfig.repo = listItem.repo;
|
||||
findProcess();
|
||||
} catch (err) {
|
||||
|
||||
console.log("[ERROR] Root -> start -> getBotConfig -> onInizialized -> onFileReceived -> err = " + err.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("[ERROR] Root -> start -> getBotConfig -> onInizialized -> err = " + err.message);
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,13 +203,12 @@ exports.newRoot = function newRoot() {
|
||||
console.log("[ERROR] Root -> start -> getBotConfig -> err.message = " + err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function findProcess() {
|
||||
|
||||
try {
|
||||
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> Entering function. "); }
|
||||
if (FULL_LOG === true) { console.log("[INFO] Root -> start -> findProcess -> Entering function. "); }
|
||||
|
||||
botConfig.process = listItem.process;
|
||||
botConfig.debug = {};
|
||||
@@ -479,7 +479,7 @@ exports.newRoot = function newRoot() {
|
||||
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess ->runExtractionBot -> pYear = " + pYear); }
|
||||
|
||||
let extractionBotMainLoop = EXTRACTION_BOT_MAIN_LOOP_MODULE.newExtractionBotMainLoop(pBotConfig);
|
||||
extractionBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
|
||||
extractionBotMainLoop.initialize(pProcessConfig, onInitializeReady);
|
||||
|
||||
function onInitializeReady(err) {
|
||||
|
||||
@@ -531,7 +531,7 @@ exports.newRoot = function newRoot() {
|
||||
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> runIndicatorBot -> pYear = " + pYear); }
|
||||
|
||||
let indicatorBotMainLoop = INDICATOR_BOT_MAIN_LOOP_MODULE.newIndicatorBotMainLoop(pBotConfig);
|
||||
indicatorBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
|
||||
indicatorBotMainLoop.initialize(pProcessConfig, onInitializeReady);
|
||||
|
||||
function onInitializeReady(err) {
|
||||
|
||||
@@ -581,7 +581,7 @@ exports.newRoot = function newRoot() {
|
||||
if (FULL_LOG === true) { logger.write("[INFO] Root -> start -> findProcess -> runTradingBot -> Entering function."); }
|
||||
|
||||
let tradingBotMainLoop = TRADING_BOT_MAIN_LOOP_MODULE.newTradingBotMainLoop(pBotConfig);
|
||||
tradingBotMainLoop.initialize(listItem.botPath, pProcessConfig, onInitializeReady);
|
||||
tradingBotMainLoop.initialize(pProcessConfig, onInitializeReady);
|
||||
|
||||
function onInitializeReady(err) {
|
||||
|
||||
|
||||
@@ -28,22 +28,87 @@
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pBotPath, pProcessConfig, callBackFunction) {
|
||||
function initialize(pProcessConfig, callBackFunction) {
|
||||
|
||||
try {
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
processConfig = pProcessConfig;
|
||||
|
||||
USER_BOT_MODULE = require(pBotPath + "/" + pProcessConfig.name + "/" + 'User.Bot');
|
||||
const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage');
|
||||
let cloudStorage = BLOB_STORAGE.newBlobStorage(bot);
|
||||
|
||||
try {
|
||||
COMMONS_MODULE = require(pBotPath + "/" + 'Commons');
|
||||
} catch (err) {
|
||||
// Nothing happens since COMMONS modules are optional.
|
||||
cloudStorage.initialize("AAPlatform", onInizialized, true);
|
||||
|
||||
function onInizialized(err) {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] initialize -> onInizialized -> Entering function."); }
|
||||
|
||||
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
let filePath = bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name;
|
||||
let fileName = "User.Bot.js";
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
USER_BOT_MODULE = {};
|
||||
USER_BOT_MODULE.newUserBot = eval(text);
|
||||
|
||||
filePath = bot.devTeam + "/" + bot.repo;
|
||||
fileName = "Commons.js";
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
// Nothing happens since COMMONS modules are optional.
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
COMMONS_MODULE = {};
|
||||
COMMONS_MODULE.newCommons = eval(text);
|
||||
|
||||
filePath = bot.devTeam + "/" + bot.repo;
|
||||
fileName = "Commons.js";
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.write("[ERROR] Root -> start -> getBotConfig -> onInizialized -> err = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
}
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] initialize -> err = " + err.message);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
|
||||
Reference in new issue
Block a user