8 files changed
+100
-254
No files matched your search
-54
@@ -1,54 +0,0 @@
|
||||
function newFileStorage() {
|
||||
|
||||
const MODULE_NAME = 'File Cloud'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
thisObject = {
|
||||
getBlobToText: getBlobToText
|
||||
};
|
||||
|
||||
return thisObject;
|
||||
|
||||
function getBlobToText(pContainerName, pPath, callBackFunction) {
|
||||
|
||||
let xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
|
||||
try {
|
||||
let response = JSON.parse(xhttp.responseText);
|
||||
callBackFunction(response.err, response.text, "");
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] AppPreLoader -> getBlobToText -> Invalid JSON received. "); }
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] AppPreLoader -> getBlobToText -> response.text = " & response.text); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE, "", "");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
let request = {
|
||||
conatinerName: pContainerName,
|
||||
path: pPath
|
||||
};
|
||||
|
||||
request = JSON.stringify(request);
|
||||
|
||||
let path = "FileService";
|
||||
|
||||
let blob = new Blob([request], { type: 'text/plain' });
|
||||
|
||||
xhttp.open("GET", path, true);
|
||||
xhttp.send(blob);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] getBlobToText -> err.message = " & err.message); }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-16
@@ -9,7 +9,7 @@ function newDailyFiles () {
|
||||
eventHandler: undefined,
|
||||
getFileCursor: getFileCursor,
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
setTimeFrame: setTimeFrame,
|
||||
getExpectedFiles: getExpectedFiles,
|
||||
getFilesLoaded: getFilesLoaded,
|
||||
initialize: initialize,
|
||||
@@ -45,22 +45,18 @@ function newDailyFiles () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) {
|
||||
try {
|
||||
callBackWhenFileReceived = callBackFunction
|
||||
|
||||
let exchange = ecosystem.getExchange(pProduct, pExchange)
|
||||
|
||||
if (exchange === undefined) {
|
||||
throw 'Exchange not supoorted by this product of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
|
||||
}
|
||||
let exchange = pExchange
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
fileCloud.initialize(pBot)
|
||||
|
||||
/* First we will get the Data Range */
|
||||
|
||||
fileCloud.getFile(pDevTeam, pBot, pSession, pSet, exchange, pMarket, undefined, undefined, undefined, true, onDataRangeReceived)
|
||||
fileCloud.getFile(pDataMine, pBot, pSession, pDataset, exchange, pMarket, undefined, undefined, undefined, true, onDataRangeReceived)
|
||||
|
||||
function onDataRangeReceived (err, pFile) {
|
||||
try {
|
||||
@@ -107,10 +103,10 @@ function newDailyFiles () {
|
||||
let periodTime = dailyFilePeriods[i][0]
|
||||
let periodName = dailyFilePeriods[i][1]
|
||||
|
||||
if (pSet.validPeriods.includes(periodName) === true) {
|
||||
if (pDataset.code.validTimeFrames.includes(periodName) === true) {
|
||||
let fileCursor = newFileCursor()
|
||||
fileCursor.eventHandler = thisObject.eventHandler // We share our event handler with each file cursor, so that they can raise events there when files are changed.s
|
||||
fileCursor.initialize(fileCloud, pDevTeam, pBot, pSession, pProduct, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onInitialized)
|
||||
fileCursor.initialize(fileCloud, pDataMine, pBot, pSession, pProduct, pDataset, exchange, pMarket, periodName, periodTime, pDatetime, pTimeFrame, beginDateRange, endDateRange, onInitialized)
|
||||
function onInitialized (err) {
|
||||
try {
|
||||
switch (err.result) {
|
||||
@@ -143,7 +139,7 @@ function newDailyFiles () {
|
||||
let periodTime = dailyFilePeriods[i][0]
|
||||
let periodName = dailyFilePeriods[i][1]
|
||||
|
||||
if (pSet.validPeriods.includes(periodName) === true) {
|
||||
if (pDataset.code.validTimeFrames.includes(periodName) === true) {
|
||||
let fileCursor = fileCursors.get(periodTime)
|
||||
fileCursor.reload(onFileReceived)
|
||||
}
|
||||
@@ -215,19 +211,19 @@ function newDailyFiles () {
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod (pTimePeriod, pDatetime) {
|
||||
function setTimeFrame (pTimeFrame, pDatetime) {
|
||||
try {
|
||||
filesLoaded = 0
|
||||
expectedFiles = 0
|
||||
fileCursors.forEach(setTimePeriodToEach)
|
||||
fileCursors.forEach(setTimeFrameToEach)
|
||||
|
||||
function setTimePeriodToEach (fileCursor, key, map) {
|
||||
fileCursor.setTimePeriod(pTimePeriod, pDatetime)
|
||||
function setTimeFrameToEach (fileCursor, key, map) {
|
||||
fileCursor.setTimeFrame(pTimeFrame, pDatetime)
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles()
|
||||
fileCursor.reload(onFileReceived)
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> err = ' + err.stack) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimeFrame -> err = ' + err.stack) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-58
@@ -22,53 +22,32 @@ function newFileCloud () {
|
||||
return thisObject
|
||||
|
||||
function initialize (pBot) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> pBot = ' + pBot.codeName) }
|
||||
|
||||
switch (STORAGE_PROVIDER) {
|
||||
case 'Azure': {
|
||||
blobService = AzureStorage.Blob.createBlobServiceWithSas(pBot.storage.fileUri, pBot.storage.sas)
|
||||
break
|
||||
}
|
||||
case 'AAWeb': {
|
||||
blobService = newFileStorage()
|
||||
break
|
||||
}
|
||||
default: {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> Storage Provider not supported -> process.env.STORAGE_PROVIDER = ' + STORAGE_PROVIDER) }
|
||||
return
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) }
|
||||
// callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); TODO> Handle this callback.
|
||||
}
|
||||
blobService = newFileStorage()
|
||||
}
|
||||
|
||||
function getFile (pDevTeam, pBot, pSession, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
function getFile (pDataMine, pBot, pSession, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFile -> Entering function.') }
|
||||
|
||||
const MAX_RETRIES = 3
|
||||
|
||||
getFileRecursively(0, pDevTeam, pBot, pSession, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
|
||||
getFileRecursively(0, pDataMine, pBot, pSession, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
|
||||
|
||||
function getFileRecursively (pRetryCounter, pDevTeam, pBot, pSession, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
function getFileRecursively (pRetryCounter, pDataMine, pBot, pSession, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pSet.filePath + '-' + pSet.fileName) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> key = ' + pDataMine.code.codeName + '-' + pBot.code.codeName + '-' + pDataset.code.filePath + '-' + pDataset.code.fileName) }
|
||||
|
||||
let fileName
|
||||
let filePath
|
||||
|
||||
if (pDataRange === undefined) {
|
||||
fileName = pSet.fileName
|
||||
filePath = pSet.filePath
|
||||
fileName = pDataset.code.fileName
|
||||
filePath = pDataset.code.filePath
|
||||
} else {
|
||||
if (pSet.dataRange !== undefined) {
|
||||
fileName = pSet.dataRange.fileName
|
||||
filePath = pSet.dataRange.filePath
|
||||
if (pDataset.code.dataRange !== undefined) {
|
||||
fileName = pDataset.code.dataRange.fileName
|
||||
filePath = pDataset.code.dataRange.filePath
|
||||
} else {
|
||||
let customErr = {
|
||||
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
|
||||
@@ -85,9 +64,9 @@ function newFileCloud () {
|
||||
|
||||
if (fileName === undefined) {
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> Inconsistant data. Check the following: ')
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pDevTeam = ' + JSON.stringify(pDevTeam))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pDataMine = ' + JSON.stringify(pDataMine))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pBot = ' + JSON.stringify(pBot))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pSet = ' + JSON.stringify(pSet))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pDataset = ' + JSON.stringify(pDataset))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pExchange = ' + JSON.stringify(pExchange))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pMarket = ' + JSON.stringify(pMarket))
|
||||
logger.write('[ERROR] getFile -> getFileRecursively -> pPeriodName = ' + JSON.stringify(pPeriodName))
|
||||
@@ -96,40 +75,31 @@ function newFileCloud () {
|
||||
}
|
||||
|
||||
if (pMarket !== undefined) {
|
||||
fileName = fileName.replace('@AssetA', pMarket.assetA)
|
||||
fileName = fileName.replace('@AssetB', pMarket.assetB)
|
||||
fileName = fileName.replace('@BaseAsset', pMarket.baseAsset)
|
||||
fileName = fileName.replace('@QuotedAsset', pMarket.quotedAsset)
|
||||
}
|
||||
|
||||
if (pDevTeam !== undefined) {
|
||||
filePath = filePath.replace('@DevTeam', pDevTeam.codeName)
|
||||
if (pDataMine !== undefined) {
|
||||
filePath = filePath.replace('@DataMine', pDataMine.code.codeName)
|
||||
}
|
||||
|
||||
if (pBot !== undefined) {
|
||||
if (pBot.cloneId !== undefined) {
|
||||
filePath = filePath.replace('@Bot', pBot.codeName + '-' + pBot.cloneId)
|
||||
} else {
|
||||
filePath = filePath.replace('@Bot', pBot.codeName)
|
||||
}
|
||||
filePath = filePath.replace('@Bot', pBot.code.codeName)
|
||||
}
|
||||
|
||||
if (pSession !== undefined) {
|
||||
let code
|
||||
let sessionFolderName = pSession.id
|
||||
if (pSession.code !== undefined) {
|
||||
try {
|
||||
code = JSON.parse(pSession.code)
|
||||
if (code.folderName !== undefined) {
|
||||
sessionFolderName = code.folderName + '-' + pSession.id
|
||||
}
|
||||
} catch (err) {
|
||||
sessionFolderName = pSession.id
|
||||
if (pSession.code.folderName !== undefined) {
|
||||
sessionFolderName = pSession.code.folderName + '-' + pSession.id
|
||||
}
|
||||
}
|
||||
filePath = filePath.replace('@Session', sessionFolderName)
|
||||
}
|
||||
|
||||
if (pExchange !== undefined) {
|
||||
filePath = filePath.replace('@Exchange', pExchange.name)
|
||||
filePath = filePath.replace('@Exchange', pExchange.code.codeName)
|
||||
}
|
||||
|
||||
filePath = filePath.replace('@Period', pPeriodName)
|
||||
@@ -149,11 +119,7 @@ function newFileCloud () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> filePath = ' + filePath) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> fileName = ' + fileName) }
|
||||
|
||||
let containerName
|
||||
|
||||
containerName = pDevTeam.codeName.toLowerCase()
|
||||
|
||||
blobService.getBlobToText(containerName, filePath + '/' + fileName, pDevTeam.host, onFileReceived)
|
||||
blobService.getBlobToText(filePath + '/' + fileName, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, text, response) {
|
||||
try {
|
||||
@@ -176,7 +142,6 @@ function newFileCloud () {
|
||||
return
|
||||
}
|
||||
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> containerName = ' + containerName) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> filePath = ' + filePath) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> fileName = ' + fileName) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Unexpected Error Ocurred.') }
|
||||
@@ -190,7 +155,7 @@ function newFileCloud () {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = ' + MAX_RETRIES) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = ' + pRetryCounter) }
|
||||
|
||||
getFileRecursively(pRetryCounter + 1, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
|
||||
getFileRecursively(pRetryCounter + 1, pDataMine, pBot, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
|
||||
return
|
||||
} else {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> Could not get this file from storage. ') }
|
||||
@@ -211,7 +176,6 @@ function newFileCloud () {
|
||||
return
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[WARN] getFile -> getFileRecursively -> onFileReceived -> err = ' + err.stack) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> containerName = ' + containerName) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> filePath = ' + filePath) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getFile -> getFileRecursively -> onFileReceived -> fileName = ' + fileName) }
|
||||
|
||||
|
||||
+25
-25
@@ -12,7 +12,7 @@ function newFileCursor () {
|
||||
eventHandler: undefined, // received from parent
|
||||
reload: reload,
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
setTimeFrame: setTimeFrame,
|
||||
files: new Map(),
|
||||
getExpectedFiles: getExpectedFiles,
|
||||
initialize: initialize,
|
||||
@@ -25,13 +25,13 @@ function newFileCursor () {
|
||||
let market
|
||||
let exchange
|
||||
let fileCloud
|
||||
let devTeam
|
||||
let dataMine
|
||||
let bot
|
||||
let session
|
||||
let product
|
||||
let thisSet
|
||||
let dataset
|
||||
let periodName
|
||||
let timePeriod
|
||||
let timeFrame
|
||||
let beginDateRange
|
||||
let endDateRange
|
||||
|
||||
@@ -52,13 +52,13 @@ function newFileCursor () {
|
||||
market = undefined
|
||||
exchange = undefined
|
||||
fileCloud = undefined
|
||||
devTeam = undefined
|
||||
dataMine = undefined
|
||||
bot = undefined
|
||||
session = undefined
|
||||
product = undefined
|
||||
thisSet = undefined
|
||||
dataset = undefined
|
||||
periodName = undefined
|
||||
timePeriod = undefined
|
||||
timeFrame = undefined
|
||||
beginDateRange = undefined
|
||||
endDateRange = undefined
|
||||
|
||||
@@ -66,33 +66,33 @@ function newFileCursor () {
|
||||
cursorDate = undefined
|
||||
fileCloud = undefined
|
||||
periodName = undefined
|
||||
timePeriod = undefined
|
||||
timeFrame = undefined
|
||||
finalized = true
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pFileCloud, pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, pPeriodName, pTimePeriod, pCursorDate, pCurrentTimePeriod, pBeginDateRange, pEndDateRange, callBackFunction) {
|
||||
function initialize (pFileCloud, pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pPeriodName, pTimeFrame, pCursorDate, pCurrentTimeFrame, pBeginDateRange, pEndDateRange, callBackFunction) {
|
||||
try {
|
||||
market = pMarket
|
||||
exchange = pExchange
|
||||
fileCloud = pFileCloud
|
||||
devTeam = pDevTeam
|
||||
dataMine = pDataMine
|
||||
bot = pBot
|
||||
session = pSession
|
||||
product = pProduct
|
||||
thisSet = pSet
|
||||
dataset = pDataset
|
||||
periodName = pPeriodName
|
||||
cursorDate = removeTime(pCursorDate)
|
||||
timePeriod = pTimePeriod
|
||||
timeFrame = pTimeFrame
|
||||
beginDateRange = pBeginDateRange
|
||||
endDateRange = pEndDateRange
|
||||
|
||||
let key = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + thisSet.codeName
|
||||
let key = dataMine.code.codeName + '-' + bot.code.codeName + '-' + product.code.codeName + '-' + dataset.code.codeName
|
||||
systemEventHandler.listenToEvent(key, 'Dataset Updated', undefined, key + '-' + periodName, onResponseDataSet, updateFiles)
|
||||
|
||||
key = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + pPeriodName
|
||||
key = dataMine.code.codeName + '-' + bot.code.codeName + '-' + product.code.codeName + '-' + pPeriodName
|
||||
systemEventHandler.listenToEvent(key, 'Data Range Updated', undefined, key, onResponseDataRange, updateDataRange)
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
@@ -147,7 +147,7 @@ function newFileCursor () {
|
||||
|
||||
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2)
|
||||
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, file) {
|
||||
try {
|
||||
@@ -167,7 +167,7 @@ function newFileCursor () {
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod (pTimePeriod, pDatetime) {
|
||||
function setTimeFrame (pTimeFrame, pDatetime) {
|
||||
try {
|
||||
if (finalized === true) { return }
|
||||
|
||||
@@ -177,7 +177,7 @@ function newFileCursor () {
|
||||
We say there is a saving mode where the cursor is running at a minimum size. When the end user aproaches the time period the cursor
|
||||
is set, then it should exit the saving mode and go to its actual size.
|
||||
|
||||
To do this we are going to measure the distance from the Time Period received to the one the cursors was initialized with.
|
||||
To do this we are going to measure the distance from the Time Frame received to the one the cursors was initialized with.
|
||||
If these periods are consecutive, it means that the cursor should exit saving mode and load its full size.
|
||||
|
||||
*/
|
||||
@@ -189,11 +189,11 @@ function newFileCursor () {
|
||||
for (let i = 0; i < dailyFilePeriods.length; i++) {
|
||||
let period = dailyFilePeriods[i]
|
||||
|
||||
if (period[0] === pTimePeriod) {
|
||||
if (period[0] === pTimeFrame) {
|
||||
positionA = i
|
||||
}
|
||||
|
||||
if (period[0] === timePeriod) {
|
||||
if (period[0] === timeFrame) {
|
||||
positionB = i
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ function newFileCursor () {
|
||||
|
||||
function enterSavingMode () {
|
||||
try {
|
||||
switch (timePeriod) {
|
||||
switch (timeFrame) {
|
||||
|
||||
case _45_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
@@ -277,13 +277,13 @@ function newFileCursor () {
|
||||
default:
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> enterSavingMode -> err = ' + err.stack) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimeFrame -> enterSavingMode -> err = ' + err.stack) }
|
||||
}
|
||||
}
|
||||
|
||||
function exitSavingMode () {
|
||||
try {
|
||||
switch (timePeriod) {
|
||||
switch (timeFrame) {
|
||||
|
||||
case _45_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
@@ -354,11 +354,11 @@ function newFileCursor () {
|
||||
default:
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> exitSavingMode -> err = ' + err.stack) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimeFrame -> exitSavingMode -> err = ' + err.stack) }
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> err = ' + err.stack) }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] setTimeFrame -> err = ' + err.stack) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ function newFileCursor () {
|
||||
if (thisObject.files.get(dateString) === undefined) {
|
||||
// We dont reload files we already have.
|
||||
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived)
|
||||
} else {
|
||||
controlLoop()
|
||||
}
|
||||
|
||||
+13
-18
@@ -20,10 +20,10 @@ function newFileSequence () {
|
||||
let files = new Map()
|
||||
let maxSequence = -1 // This is replaced by the content of the sequence file, which contains an index that starts on zero. In the case that the sequence file is not found the default value is -1 so when you add 1 it gives you the amount of files in the sequence, zero.
|
||||
let market
|
||||
let devTeam
|
||||
let dataMine
|
||||
let bot
|
||||
let session
|
||||
let thisSet
|
||||
let dataset
|
||||
let product
|
||||
let finalized = false
|
||||
let initialized = false
|
||||
@@ -47,10 +47,10 @@ function newFileSequence () {
|
||||
files = undefined
|
||||
maxSequence = undefined
|
||||
market = undefined
|
||||
devTeam = undefined
|
||||
dataMine = undefined
|
||||
bot = undefined
|
||||
session = undefined
|
||||
thisSet = undefined
|
||||
dataset = undefined
|
||||
product = undefined
|
||||
|
||||
finalized = true
|
||||
@@ -59,19 +59,14 @@ function newFileSequence () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) {
|
||||
try {
|
||||
exchange = ecosystem.getExchange(pProduct, pExchange)
|
||||
|
||||
if (exchange === undefined) {
|
||||
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
|
||||
}
|
||||
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
devTeam = pDevTeam
|
||||
dataMine = pDataMine
|
||||
bot = pBot
|
||||
session = pSession
|
||||
thisSet = pSet
|
||||
dataset = pDataset
|
||||
product = pProduct
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
@@ -79,7 +74,7 @@ function newFileSequence () {
|
||||
|
||||
callerId = newUniqueId()
|
||||
|
||||
let key = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + thisSet.codeName
|
||||
let key = dataMine.code.codeName + '-' + bot.code.codeName + '-' + product.code.codeName + '-' + dataset.code.codeName
|
||||
systemEventHandler.listenToEvent(key, 'Dataset Updated', undefined, callerId, onResponse, updateFiles)
|
||||
|
||||
function onResponse (message) {
|
||||
@@ -88,7 +83,7 @@ function newFileSequence () {
|
||||
|
||||
/* First we will get the sequence max number */
|
||||
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
|
||||
|
||||
function onSequenceFileReceived (err, file) {
|
||||
try {
|
||||
@@ -133,7 +128,7 @@ function newFileSequence () {
|
||||
/* Now we will get the sequence of files */
|
||||
|
||||
for (let i = 0; i <= maxSequence; i++) {
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived)
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, undefined, undefined, i, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, file) {
|
||||
try {
|
||||
@@ -198,7 +193,7 @@ function newFileSequence () {
|
||||
|
||||
let currentMaxSequence = maxSequence
|
||||
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived)
|
||||
|
||||
function onSequenceFileReceived (err, sequenceFile) {
|
||||
try {
|
||||
@@ -234,7 +229,7 @@ function newFileSequence () {
|
||||
/* Now we will get the sequence of files, but in this case only from the currentMaxSequence and above. */
|
||||
|
||||
for (let i = currentMaxSequence; i <= maxSequence; i++) {
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived)
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, undefined, undefined, i, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, file) {
|
||||
try {
|
||||
|
||||
+11
-55
@@ -1,5 +1,5 @@
|
||||
function newFileStorage() {
|
||||
const MODULE_NAME = 'File Cloud'
|
||||
function newFileStorage () {
|
||||
const MODULE_NAME = 'File Storage'
|
||||
const INFO_LOG = false
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
@@ -29,66 +29,22 @@ function newFileStorage() {
|
||||
|
||||
return thisObject
|
||||
|
||||
async function getBlobToText(container, filePath, host, callBackFunction) {
|
||||
async function getBlobToText (filePath, host, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getBlobToText -> Entering function.') }
|
||||
|
||||
if (host.url.indexOf('localhost') !== -1) {
|
||||
callServer(undefined, 'Storage/' + container + '/' + filePath, (response, fileContent) => {
|
||||
if (response.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, fileContent)
|
||||
} else {
|
||||
callBackFunction(response)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let headers
|
||||
let accessToken = window.localStorage.getItem('access_token')
|
||||
if (accessToken !== null) {
|
||||
headers = {
|
||||
authorization: 'Bearer ' + accessToken
|
||||
}
|
||||
}
|
||||
|
||||
let response = await axios({
|
||||
url: host.url + 'graphql',
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
query web_FileContent($file: web_FileInput){
|
||||
web_FileContent(file: $file)
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
file: {
|
||||
container: container.toLowerCase(),
|
||||
filePath,
|
||||
storage: host.storage,
|
||||
accessKey: host.accessKey
|
||||
}
|
||||
}
|
||||
},
|
||||
headers: headers
|
||||
})
|
||||
|
||||
if (response.data.errors) {
|
||||
let error = { code: response.data.errors[0] }
|
||||
callBackFunction(error)
|
||||
return
|
||||
}
|
||||
|
||||
if (response.data.data.web_FileContent) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, response.data.data.web_FileContent)
|
||||
callServer(undefined, 'Storage/' + filePath, (response, fileContent) => {
|
||||
if (response.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, fileContent)
|
||||
} else {
|
||||
callBackFunction({ code: 'The specified key does not exist.' })
|
||||
callBackFunction(response)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
} catch (err) {
|
||||
if (verifyRetry(err.code) && currentRetry < MAX_RETRY) {
|
||||
currentRetry++
|
||||
if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Retrying connection to the server because received error: ' + err.code + '. Retry #: ' + currentRetry) }
|
||||
getBlobToText(container, filePath, host, callBackFunction)
|
||||
getBlobToText(filePath, host, callBackFunction)
|
||||
} else if (err.message === 'Request aborted') {
|
||||
let err = { code: 'The specified key does not exist.' }
|
||||
callBackFunction(err)
|
||||
@@ -99,9 +55,9 @@ function newFileStorage() {
|
||||
}
|
||||
}
|
||||
|
||||
function verifyRetry(errorCode) {
|
||||
function verifyRetry (errorCode) {
|
||||
for (let i = 0; i < recoverableErrors.length; i++) {
|
||||
const error = recoverableErrors[i];
|
||||
const error = recoverableErrors[i]
|
||||
if (error === errorCode) {
|
||||
return true
|
||||
}
|
||||
|
||||
+13
-18
@@ -24,10 +24,10 @@ function newMarketFiles () {
|
||||
|
||||
let market
|
||||
let exchange
|
||||
let devTeam
|
||||
let dataMine
|
||||
let bot
|
||||
let session
|
||||
let thisSet
|
||||
let dataset
|
||||
let product
|
||||
let periodName
|
||||
|
||||
@@ -52,10 +52,10 @@ function newMarketFiles () {
|
||||
|
||||
market = undefined
|
||||
exchange = undefined
|
||||
devTeam = undefined
|
||||
dataMine = undefined
|
||||
bot = undefined
|
||||
session = undefined
|
||||
thisSet = undefined
|
||||
dataset = undefined
|
||||
product = undefined
|
||||
periodName = undefined
|
||||
|
||||
@@ -65,19 +65,14 @@ function newMarketFiles () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) {
|
||||
try {
|
||||
exchange = ecosystem.getExchange(pProduct, pExchange)
|
||||
|
||||
if (exchange === undefined) {
|
||||
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
|
||||
}
|
||||
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
devTeam = pDevTeam
|
||||
dataMine = pDataMine
|
||||
bot = pBot
|
||||
session = pSession
|
||||
thisSet = pSet
|
||||
dataset = pDataset
|
||||
product = pProduct
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
@@ -89,8 +84,8 @@ function newMarketFiles () {
|
||||
let periodTime = marketFilesPeriods[i][0]
|
||||
let periodName = marketFilesPeriods[i][1]
|
||||
|
||||
if (thisSet.validPeriods.includes(periodName) === true) {
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived)
|
||||
if (dataset.code.validTimeFrames.includes(periodName) === true) {
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, periodName, undefined, undefined, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, file) {
|
||||
try {
|
||||
@@ -103,7 +98,7 @@ function newMarketFiles () {
|
||||
}
|
||||
|
||||
if (filesLoaded + filesNotLoaded === marketFilesPeriods.length) {
|
||||
let key = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + thisSet.codeName
|
||||
let key = dataMine.code.codeName + '-' + bot.code.codeName + '-' + product.code.codeName + '-' + dataset.code.codeName
|
||||
systemEventHandler.listenToEvent(key, 'Dataset Updated', undefined, key + '-' + periodName, onResponse, updateFiles)
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject)
|
||||
@@ -136,8 +131,8 @@ function newMarketFiles () {
|
||||
let periodTime = marketFilesPeriods[i][0]
|
||||
let periodName = marketFilesPeriods[i][1]
|
||||
|
||||
if (thisSet.validPeriods.includes(periodName) === true) {
|
||||
fileCloud.getFile(devTeam, bot, session, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived)
|
||||
if (dataset.code.validTimeFrames.includes(periodName) === true) {
|
||||
fileCloud.getFile(dataMine, bot, session, dataset, exchange, market, periodName, undefined, undefined, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, file) {
|
||||
try {
|
||||
|
||||
+4
-10
@@ -16,25 +16,19 @@ function newSingleFile () {
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize (pDevTeam, pBot, pSession, pProduct, pSet, pExchange, pMarket, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDataMine.code.codeName + '-' + pBot.code.codeName + '-' + pProduct.code.codeName) }
|
||||
|
||||
let exchange = ecosystem.getExchange(pProduct, pExchange)
|
||||
|
||||
if (pExchange !== undefined && exchange === undefined) {
|
||||
// We support no exchange as a parameter, but if provided, then it must be at the list of exchanges of that product.
|
||||
|
||||
throw 'Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = ' + pDevTeam.codeName + ', pBot.codeName = ' + pBot.codeName + ', pProduct.codeName = ' + pProduct.codeName + ', pExchange = ' + pExchange
|
||||
}
|
||||
let exchange = pExchange
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
fileCloud.initialize(pBot)
|
||||
|
||||
/* Now we will get the file */
|
||||
|
||||
fileCloud.getFile(pDevTeam, pBot, pSession, pSet, exchange, pMarket, undefined, undefined, undefined, undefined, onFileReceived)
|
||||
fileCloud.getFile(pDataMine, pBot, pSession, pDataset, exchange, pMarket, undefined, undefined, undefined, undefined, onFileReceived)
|
||||
|
||||
function onFileReceived (err, pFile) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user