From 43e1717cdc9f5503f7e23f52368e8596cb765408 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 15 Apr 2018 13:43:00 +0200 Subject: [PATCH] statusDependencies at Trading Main Loop Implemented --- .vs/AACloud/v15/.suo | Bin 86528 -> 77312 bytes Data Dependencies.js | 140 +++++++++++++++++++++++++++- Extraction Bot Process Main Loop.js | 22 ++--- Indicator Bot Process Main Loop.js | 22 ++--- Status Dependencies.js | 28 +++--- Trading Bot Process Main Loop.js | 57 ++++++++--- 6 files changed, 220 insertions(+), 49 deletions(-) diff --git a/.vs/AACloud/v15/.suo b/.vs/AACloud/v15/.suo index 99a79072a055022a2ec4c4e7178363e7cfa7cc29..c4e15f92b9d76e07f0c8245860ff17dd66ad8f59 100644 GIT binary patch delta 2964 zcmb`Je^6A{702JXy9>L3$ntCXB`hl{qPA#_K}yL|QK|B40d0N|;%_TS(8yvCjk{Pi z9YPH3RbFDO#V56N{4rr)Q<9E}n%Yd#WTu)r{?TE~nx->0GD)Y^nQD#O?}4`s$xPdS zygQ#c=bm%lz4zVk-Fu&Zz~Ub<_mremDvDwT_rl>Yj6xuD$df5-{@y1yoWA@=s+VoT zM??B85la*!$(+=?#q8tu51}ngI1lzgFdcjgB!VcA51haa62Lsb?YX4GF9MUm46qe^ ziTHP5p8#=S7nlZO!Bo%+CW9J9k*YPY=eCkw1e%S1MCExD>G~-th`HGY|i4@YgnfrPSDB6 zExB0GikFpNr_^|oW&0jr*|-hM#+GGc8$eqlW*IqRjl7 zZaa`LbW_scXMh6meIN&|S-y2}ssM}U0XzbW$CgV(Jbn`{KR_-Suy|Z&@#cex!VVZY z&ey@`4YAUQ@oGf0gF8LE2#J|Sas_M(SOy*jj{w&3F}cZ-XG&Gr3x)s1merB{8tb__E+S} zLJ=MH6I8xArKEZ@?~h0u%h>$%+m1g7`CjT>{X%Am28|#)gY-Gl|H@lkxKZ@3)-M5ppe4(wh28%30Mx`X`j#W1-a(97Kx;l=^ z--@~NW=FU57r3N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T z1sW}FQ8ZrbzT+Y5d0Z;i%cOgdZM$qYVG!~jDKA(dRh~Q^L9vc7j0=_VaN+=;*HF8d zyJPCWX{Z-}pKce;)$#m}=wxv+70T1$6vJ!hi^X3Xl?syl1^#&&r?E&^B&2_9GX33 zjfkUEIxQFfwiG{;yH1e3s3nJ%%f~xdme$Z@Io3#>a+3*bO*T;ir?P|}+<{_%mo8rp zr|0D*BR%)w2E3zYsUXblp${BRyldW`X*qS4S7tu12oL*O*ziT3uk?5Xo_uJFx zI+<2{8jg?aMDfX|r6-Cq#ik{3kty@suD>PRSX#UEQhN5Z{h9uzXsRJv>8EJwCvmeY z$)6NQS52a|C(WOhLSK;l*hYQBA_?q%1d*-&d1-Wl#5>hdvL~JFgKy*1(5>UJM!Jpo zZ`XQVt?pR=KZ{S>XYN}%_i)uo(}`u`R8gSZyh(f=An=6gFDfZK?Qza2IUjID7RDw@sjbkldO@pNXA~GeuKl{t()hC;bP+eVe=h diff --git a/Data Dependencies.js b/Data Dependencies.js index 5f282702b..8de8f4b7b 100644 --- a/Data Dependencies.js +++ b/Data Dependencies.js @@ -1 +1,139 @@ - \ No newline at end of file +exports.newDataDependencies = function newDataDependencies(BOT, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES) { + + const FULL_LOG = true; + const LOG_FILE_CONTENT = false; + + const MODULE_NAME = "Data Dependencies"; + + let thisObject = { + statusReports: new Map(), + initialize: initialize, + keys: [] + }; + + let bot = BOT; + let ownerBot; // This is the bot owner of the Status Report. Only owners can save the report and override the existing content. + + const logger = DEBUG_MODULE.newDebugLog(); + logger.fileName = MODULE_NAME; + logger.bot = bot; + + return thisObject; + + function initialize(pDataDependenciesConfig, pMonth, pYear, callBackFunction) { + + try { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + + /* + + For each dependency declared at the bot config, we will initialize the status report, and load it as part of this initialization process. + + */ + let alreadyCalledBack = false; + let loadCount = 0; + + for (let i = 0; i < pDataDependenciesConfig.length; i++) { + + let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, BLOB_STORAGE, UTILITIES); + + statusReportModule.initialize(pDataDependenciesConfig[i], pMonth, pYear, onInitilized); + + function onInitilized(err) { + + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write("[ERROR] initialize -> onInitilized -> err = " + err.message); + + alreadyCalledBack = true; + callBackFunction(err); + return; + } + + statusReportModule.load(onLoad); + } + + function onLoad(err) { + + try { + + statusReportModule.status = err.message; + + switch (err.message) { + case global.DEFAULT_OK_RESPONSE.message: { + logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pDataDependenciesConfig[i].bot); + logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pDataDependenciesConfig[i].process); + + addReport(); + return; + } + case "Status Report was never created.": { + + logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDataDependenciesConfig[i].bot); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDataDependenciesConfig[i].process); + addReport(); + return; + } + + case "Status Report is corrupt.": { + + logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDataDependenciesConfig[i].bot); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDataDependenciesConfig[i].process); + addReport(); + return; + } + default: + { + logger.write("[ERROR] initialize -> onLoad -> Operation Failed."); + + if (alreadyCalledBack === false) { + alreadyCalledBack = true; + callBackFunction(err); + } + return; + } + } + } + catch (err) { + logger.write("[ERROR] initialize -> onLoad -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + + function addReport() { + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Entering function."); } + + loadCount++; + + let key; + + if (pDataDependenciesConfig[i].dataSetSection === "Month") { + key = pDataDependenciesConfig[i].devTeam + "-" + pDataDependenciesConfig[i].bot + "-" + pDataDependenciesConfig[i].process + "-" + pDataDependenciesConfig[i].dataSetVersion + "-" + pYear + "-" + pMonth; + } else { + key = pDataDependenciesConfig[i].devTeam + "-" + pDataDependenciesConfig[i].bot + "-" + pDataDependenciesConfig[i].process + "-" + pDataDependenciesConfig[i].dataSetVersion; + } + + thisObject.keys.push(key); + thisObject.statusReports.set(key, statusReportModule); + + if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); } + + if (loadCount === pDataDependenciesConfig.length) { + if (alreadyCalledBack === false) { + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; + } + } + } + } + + } catch (err) { + logger.write("[ERROR] initialize -> err = " + err.message); + callBackFunction(global.DEFAULT_FAIL_RESPONSE); + } + } + +}; \ No newline at end of file diff --git a/Extraction Bot Process Main Loop.js b/Extraction Bot Process Main Loop.js index 0ae330233..bc05f9e1c 100644 --- a/Extraction Bot Process Main Loop.js +++ b/Extraction Bot Process Main Loop.js @@ -67,7 +67,7 @@ const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); const STATUS_REPORT = require(ROOT_DIR + 'Status Report'); const POLONIEX_CLIENT_MODULE = require(ROOT_DIR + 'Poloniex API Client'); - const DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies'); + const STATUS_DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies'); /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ @@ -76,36 +76,36 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ let userBot; - let dependencies; + let statusDependencies; let nextWaitTime; - initializeDependencies(); + initializeStatusDependencies(); - function initializeDependencies() { + function initializeStatusDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - dependencies = DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); - dependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); + statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); function onInizialized(err) { switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)"); + logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)"); initializeUserBot(); return; } 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 -> initializeDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); nextWaitTime = 'Retry'; loopControl(nextWaitTime); return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeDependencies -> onInizialized > Operation Failed. Aborting the process."); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process."); callBackFunction(err); return; } @@ -119,7 +119,7 @@ usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, STATUS_REPORT, POLONIEX_CLIENT_MODULE); - usertBot.initialize(dependencies, pMonth, pYear, onInizialized); + usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); function onInizialized(err) { diff --git a/Indicator Bot Process Main Loop.js b/Indicator Bot Process Main Loop.js index 7485cf5ba..d67faa7e8 100644 --- a/Indicator Bot Process Main Loop.js +++ b/Indicator Bot Process Main Loop.js @@ -67,7 +67,7 @@ const FILE_STORAGE = require(ROOT_DIR + 'File Storage'); const DEBUG_MODULE = require(ROOT_DIR + 'Debug Log'); const STATUS_REPORT = require(ROOT_DIR + 'Status Report'); - const DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies'); + const STATUS_DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies'); /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ @@ -76,36 +76,36 @@ /* We will prepare first the infraestructure needed for the bot to run. There are 3 modules we need to sucessfullly initialize first. */ let userBot; - let dependencies; + let statusDependencies; let nextWaitTime; - initializeDependencies(); + initializeStatusDependencies(); - function initializeDependencies() { + function initializeStatusDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - dependencies = DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); - dependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); + statusDependencies.initialize(processConfig.statusDependencies, pMonth, pYear, onInizialized); function onInizialized(err) { switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)"); + logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)"); initializeUserBot(); return; } 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 -> initializeDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); nextWaitTime = 'Retry'; loopControl(nextWaitTime); return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeDependencies -> onInizialized > Operation Failed. Aborting the process."); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process."); callBackFunction(err); return; } @@ -119,7 +119,7 @@ usertBot = USER_BOT_MODULE.newUserBot(bot, COMMONS_MODULE, UTILITIES, DEBUG_MODULE, BLOB_STORAGE, FILE_STORAGE); - usertBot.initialize(dependencies, pMonth, pYear, onInizialized); + usertBot.initialize(statusDependencies, pMonth, pYear, onInizialized); function onInizialized(err) { diff --git a/Status Dependencies.js b/Status Dependencies.js index 3b7d124de..c55e2c5e1 100644 --- a/Status Dependencies.js +++ b/Status Dependencies.js @@ -3,7 +3,7 @@ const FULL_LOG = true; const LOG_FILE_CONTENT = false; - const MODULE_NAME = "Dependencies"; + const MODULE_NAME = "Status Dependencies"; let thisObject = { statusReports: new Map(), @@ -20,7 +20,7 @@ return thisObject; - function initialize(pDependenciesConfig, pMonth, pYear, callBackFunction) { + function initialize(pStatusDependenciesConfig, pMonth, pYear, callBackFunction) { try { @@ -34,11 +34,11 @@ let alreadyCalledBack = false; let loadCount = 0; - for (let i = 0; i < pDependenciesConfig.length; i++) { + for (let i = 0; i < pStatusDependenciesConfig.length; i++) { let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, BLOB_STORAGE, UTILITIES); - statusReportModule.initialize(pDependenciesConfig[i], pMonth, pYear, onInitilized); + statusReportModule.initialize(pStatusDependenciesConfig[i], pMonth, pYear, onInitilized); function onInitilized(err) { @@ -61,8 +61,8 @@ switch (err.message) { case global.DEFAULT_OK_RESPONSE.message: { - logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pDependenciesConfig[i].bot); - logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pDependenciesConfig[i].process); + logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pStatusDependenciesConfig[i].bot); + logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pStatusDependenciesConfig[i].process); addReport(); return; @@ -70,8 +70,8 @@ case "Status Report was never created.": { logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message); - logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDependenciesConfig[i].bot); - logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDependenciesConfig[i].process); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process); addReport(); return; } @@ -79,8 +79,8 @@ case "Status Report is corrupt.": { logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message); - logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pDependenciesConfig[i].bot); - logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pDependenciesConfig[i].process); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot); + logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process); addReport(); return; } @@ -110,10 +110,10 @@ let key; - if (pDependenciesConfig[i].dataSetSection === "Month") { - key = pDependenciesConfig[i].devTeam + "-" + pDependenciesConfig[i].bot + "-" + pDependenciesConfig[i].process + "-" + pDependenciesConfig[i].dataSetVersion + "-" + pYear + "-" + pMonth; + if (pStatusDependenciesConfig[i].dataSetSection === "Month") { + key = pStatusDependenciesConfig[i].devTeam + "-" + pStatusDependenciesConfig[i].bot + "-" + pStatusDependenciesConfig[i].process + "-" + pStatusDependenciesConfig[i].dataSetVersion + "-" + pYear + "-" + pMonth; } else { - key = pDependenciesConfig[i].devTeam + "-" + pDependenciesConfig[i].bot + "-" + pDependenciesConfig[i].process + "-" + pDependenciesConfig[i].dataSetVersion; + key = pStatusDependenciesConfig[i].devTeam + "-" + pStatusDependenciesConfig[i].bot + "-" + pStatusDependenciesConfig[i].process + "-" + pStatusDependenciesConfig[i].dataSetVersion; } thisObject.keys.push(key); @@ -121,7 +121,7 @@ if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); } - if (loadCount === pDependenciesConfig.length) { + if (loadCount === pStatusDependenciesConfig.length) { if (alreadyCalledBack === false) { callBackFunction(global.DEFAULT_OK_RESPONSE); return; diff --git a/Trading Bot Process Main Loop.js b/Trading Bot Process Main Loop.js index 4f437e415..a4b9de001 100644 --- a/Trading Bot Process Main Loop.js +++ b/Trading Bot Process Main Loop.js @@ -71,7 +71,8 @@ const DATASOURCE = require(ROOT_DIR + 'Datasource'); const ASSISTANT = require(ROOT_DIR + 'Assistant'); const STATUS_REPORT = require(ROOT_DIR + 'Status Report'); - const DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies'); + const STATUS_DEPENDENCIES = require(ROOT_DIR + 'Status Dependencies'); + const DATA_DEPENDENCIES = require(ROOT_DIR + 'Data Dependencies'); /* We define the datetime for the process that we are running now. This will be the official processing time for both the infraestructure and the bot. */ @@ -84,36 +85,68 @@ let exchangeAPI; let assistant; let userBot; - let dependencies; + let statusDependencies; + let dataDependencies; let nextWaitTime; - initializeDependencies(); + initializeStatusDependencies(); - function initializeDependencies() { + function initializeStatusDependencies() { - if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDependencies -> Entering function."); } + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeStatusDependencies -> Entering function."); } - dependencies = DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + statusDependencies = STATUS_DEPENDENCIES.newStatusDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); - dependencies.initialize(processConfig.statusDependencies, undefined, undefined, onInizialized); + statusDependencies.initialize(processConfig.statusDependencies, undefined, undefined, onInizialized); function onInizialized(err) { switch (err.result) { case global.DEFAULT_OK_RESPONSE.result: { - logger.write("[INFO] run -> loop -> initializeDependencies -> onInizialized > Execution finished well. :-)"); - initializeContext(); + logger.write("[INFO] run -> loop -> initializeStatusDependencies -> onInizialized > Execution finished well. :-)"); + initializeDataDependencies(); return; } 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 -> initializeDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); nextWaitTime = 'Retry'; loopControl(nextWaitTime); return; } case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. - logger.write("[ERROR] run -> loop -> initializeDependencies -> onInizialized > Operation Failed. Aborting the process."); + logger.write("[ERROR] run -> loop -> initializeStatusDependencies -> onInizialized > Operation Failed. Aborting the process."); + callBackFunction(err); + return; + } + } + } + } + + function initializeDataDependencies() { + + if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeDataDependencies -> Entering function."); } + + dataDependencies = DATA_DEPENDENCIES.newDataDependencies(bot, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES); + + dataDependencies.initialize(processConfig.dataDependencies, undefined, undefined, onInizialized); + + function onInizialized(err) { + + switch (err.result) { + case global.DEFAULT_OK_RESPONSE.result: { + logger.write("[INFO] run -> loop -> initializeDataDependencies -> onInizialized > Execution finished well. :-)"); + initializeContext(); + return; + } + 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 -> initializeDataDependencies -> onInizialized > Retry Later. Requesting Execution Retry."); + nextWaitTime = 'Retry'; + loopControl(nextWaitTime); + return; + } + case global.DEFAULT_FAIL_RESPONSE.result: { // This is an unexpected exception that we do not know how to handle. + logger.write("[ERROR] run -> loop -> initializeDataDependencies -> onInizialized > Operation Failed. Aborting the process."); callBackFunction(err); return; } @@ -126,7 +159,7 @@ if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> initializeContext -> Entering function."); } context = CONTEXT.newContext(bot, DEBUG_MODULE, BLOB_STORAGE, UTILITIES, STATUS_REPORT); - context.initialize(dependencies, onInizialized); + context.initialize(statusDependencies, onInizialized); function onInizialized(err) {