From d761dc4a7c9b15f5302e0eb68a6223a083b873e1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 14:54:22 +0200 Subject: [PATCH 1/4] Sequence Files Initialization Fixed --- src/FileSequence.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/FileSequence.js b/src/FileSequence.js index cfca4992d..9d194024c 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -87,7 +87,6 @@ function newFileSequence () { function onSequenceFileReceived (err, file) { try { if (finalized === true) { return } - initialized = true switch (err.result) { case GLOBAL.DEFAULT_OK_RESPONSE.result: { @@ -101,14 +100,18 @@ function newFileSequence () { case GLOBAL.CUSTOM_OK_RESPONSE.result: { if (ERROR_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> err.message = ' + err.message) } - + initialized = true callBackFunction(err) return } case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + if (err.message === 'File does not exist.') { // We will assume that the process which generates the files has never been started, that does not imply that we can wait for data to come later. + initialized = true + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) + return + } if (ERROR_LOG === true) { logger.write('[INFO] initialize -> onSequenceFileReceived -> err.message = ' + err.message) } - callBackFunction(err, thisObject) return } @@ -118,7 +121,7 @@ function newFileSequence () { return } } - + initialized = true maxSequence = Number(file) /* Now we will get the sequence of files */ From b5d85a82e09a4c7973effbf7e917aae62cdb6c30 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 17:21:40 +0200 Subject: [PATCH 2/4] FileSequence connected by events --- src/FileSequence.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FileSequence.js b/src/FileSequence.js index 9d194024c..cfd0cfaf4 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -73,8 +73,10 @@ function newFileSequence () { fileCloud = newFileCloud() fileCloud.initialize(bot) + let callerId = newUniqueId() + let key = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + thisSet.codeName - systemEventHandler.listenToEvent(key, 'Dataset Updated', undefined, key, onResponse, updateFiles) + systemEventHandler.listenToEvent(key, 'Dataset Updated', undefined, callerId, onResponse, updateFiles) function onResponse (message) { eventSubscriptionIdDatasetUpdated = message.eventSubscriptionId From 74915e23ce82ae38faf353c8ed202872e74ef9f0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 23 Sep 2019 18:04:33 +0200 Subject: [PATCH 3/4] File Sequence Fixed --- src/FileSequence.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/FileSequence.js b/src/FileSequence.js index cfd0cfaf4..a42bb9e7d 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -30,6 +30,7 @@ function newFileSequence () { thisObject.eventHandler = newEventHandler() let eventSubscriptionIdDatasetUpdated + let callerId return thisObject @@ -73,7 +74,7 @@ function newFileSequence () { fileCloud = newFileCloud() fileCloud.initialize(bot) - let callerId = newUniqueId() + callerId = newUniqueId() let key = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + thisSet.codeName systemEventHandler.listenToEvent(key, 'Dataset Updated', undefined, callerId, onResponse, updateFiles) @@ -198,7 +199,7 @@ function newFileSequence () { fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, 'Sequence', undefined, onSequenceFileReceived) - function onSequenceFileReceived (err, file) { + function onSequenceFileReceived (err, sequenceFile) { try { if (finalized === true) { return } switch (err.result) { @@ -226,7 +227,8 @@ function newFileSequence () { } } - maxSequence = Number(file) + maxSequence = Number(sequenceFile) + filesLoaded = 0 /* Now we will get the sequence of files, but in this case only from the currentMaxSequence and above. */ @@ -240,26 +242,18 @@ function newFileSequence () { case GLOBAL.DEFAULT_OK_RESPONSE.result: { break } - case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { return } - case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { if (ERROR_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) } return } - - default: { - return - } } files.set(i, file) - if (i !== currentMaxSequence) { - filesLoaded++ - } + filesLoaded++ if (filesLoaded === maxSequence + 1) { thisObject.eventHandler.raiseEvent('Files Updated', undefined) From 3632ace5b833841904e405c78a63b1f668f1baea Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 25 Sep 2019 09:34:46 +0200 Subject: [PATCH 4/4] Better logging --- src/FileSequence.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/FileSequence.js b/src/FileSequence.js index a42bb9e7d..8fffd7c03 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -183,8 +183,6 @@ function newFileSequence () { try { if (finalized === true || initialized === false) { return } - logger.write('[INFO] updateFiles -> Entering function.') - /* To keep this data structure up-to-date we need to: @@ -212,17 +210,17 @@ function newFileSequence () { } case GLOBAL.CUSTOM_OK_RESPONSE.result: { - if (ERROR_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) } + if (ERROR_LOG === true) { logger.write('[WARN] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) } return } case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { - if (ERROR_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) } + if (ERROR_LOG === true) { logger.write('[WARN] updateFiles -> onSequenceFileReceived -> err.message = ' + err.message) } return } default: { - if (ERROR_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> Received Unexpected Response.') } + if (ERROR_LOG === true) { logger.write('[WARN] updateFiles -> onSequenceFileReceived -> Received Unexpected Response.') } return } } @@ -246,7 +244,7 @@ function newFileSequence () { return } case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { - if (ERROR_LOG === true) { logger.write('[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) } + if (ERROR_LOG === true) { logger.write('[WARN] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = ' + err.message) } return } }