host and pot implementation
This commit is contained in:
1 parent
50264e9675
commit
5ed0fcaa23
6 files changed
+23
-18
No files matched your search
+2
-2
@@ -45,14 +45,14 @@ function newDailyFiles () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, pHost, pPort, callBackFunction) {
|
||||
try {
|
||||
callBackWhenFileReceived = callBackFunction
|
||||
|
||||
let exchange = pExchange
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
fileCloud.initialize(pBot)
|
||||
fileCloud.initialize(pBot, pHost, pPort)
|
||||
|
||||
/* Some Validations */
|
||||
if (pDataset.code.validTimeFrames === undefined) {
|
||||
|
||||
+4
-4
@@ -17,12 +17,12 @@ function newFileCloud () {
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let blobService
|
||||
let fileStorage
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize (pBot) {
|
||||
blobService = newFileStorage()
|
||||
function initialize (pBot, pHost, pPort) {
|
||||
fileStorage = newFileStorage(pHost, pPort)
|
||||
}
|
||||
|
||||
function getFile (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
@@ -121,7 +121,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) }
|
||||
|
||||
blobService.getBlobToText(filePath + '/' + fileName, undefined, onFileReceived)
|
||||
fileStorage.getFileFromHost(filePath + '/' + fileName, onFileReceived)
|
||||
|
||||
function onFileReceived (err, text, response) {
|
||||
try {
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ function newFileSequence () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pHost, pPort, callBackFunction) {
|
||||
try {
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
@@ -70,7 +70,7 @@ function newFileSequence () {
|
||||
product = pProduct
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
fileCloud.initialize(bot)
|
||||
fileCloud.initialize(bot, pHost, pPort)
|
||||
|
||||
callerId = newUniqueId()
|
||||
|
||||
|
||||
+11
-6
@@ -1,4 +1,4 @@
|
||||
function newFileStorage () {
|
||||
function newFileStorage (host, port) {
|
||||
const MODULE_NAME = 'File Storage'
|
||||
const INFO_LOG = false
|
||||
const logger = newWebDebugLog()
|
||||
@@ -24,20 +24,25 @@ function newFileStorage () {
|
||||
]
|
||||
|
||||
let thisObject = {
|
||||
getBlobToText: getBlobToText
|
||||
getFileFromHost: getFileFromHost
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
async function getBlobToText (filePath, host, callBackFunction, pathComplete) {
|
||||
async function getFileFromHost (filePath, callBackFunction, pathComplete) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getBlobToText -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getFileFromHost -> Entering function.') }
|
||||
|
||||
let folder = ''
|
||||
if (pathComplete === false || pathComplete === undefined) {
|
||||
folder = 'Storage/'
|
||||
}
|
||||
callServer(undefined, folder + filePath, (response, fileContent) => {
|
||||
let url = folder + filePath
|
||||
if (host !== undefined) {
|
||||
url = 'http://' + host + ':' + port + '/' + folder + filePath
|
||||
}
|
||||
|
||||
callServer(undefined, url, (response, fileContent) => {
|
||||
if (response.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, fileContent)
|
||||
} else {
|
||||
@@ -48,7 +53,7 @@ function newFileStorage () {
|
||||
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(filePath, host, callBackFunction)
|
||||
getFileFromHost(filePath, callBackFunction)
|
||||
} else if (err.message === 'Request aborted') {
|
||||
let err = { code: 'The specified key does not exist.' }
|
||||
callBackFunction(err)
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ function newMarketFiles () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pHost, pPort, callBackFunction) {
|
||||
try {
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
@@ -78,7 +78,7 @@ function newMarketFiles () {
|
||||
product = pProduct
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
fileCloud.initialize(pBot)
|
||||
fileCloud.initialize(pBot, pHost, pPort)
|
||||
|
||||
/* Some Validations */
|
||||
if (dataset.code.validTimeFrames === undefined) {
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ function newSingleFile () {
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) {
|
||||
function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pHost, pPort, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDataMine.code.codeName + '-' + pBot.code.codeName + '-' + pProduct.code.codeName) }
|
||||
@@ -24,7 +24,7 @@ function newSingleFile () {
|
||||
let exchange = pExchange
|
||||
|
||||
fileCloud = newFileCloud()
|
||||
fileCloud.initialize(pBot)
|
||||
fileCloud.initialize(pBot, pHost, pPort)
|
||||
|
||||
/* Now we will get the file */
|
||||
|
||||
|
||||
Reference in new issue
Block a user