diff --git a/AzureBlobStorage.js b/AzureBlobStorage.js index ac05d5eb9..125966315 100644 --- a/AzureBlobStorage.js +++ b/AzureBlobStorage.js @@ -299,7 +299,8 @@ exports.newAzureBlobBlobStorage = function newAzureBlobBlobStorage(BOT, logger) err.code === 'EAI_AGAIN' || err.code === 'AuthenticationFailed' || err.code === 'OperationTimedOut' || - err.code === 'ServerBusy' + err.code === 'ServerBusy' || + text === undefined ) { setTimeout(secondTry, SECOND_TRY_WAIT_TIME); diff --git a/Context.js b/Context.js index dd864ee22..ab0f38656 100644 --- a/Context.js +++ b/Context.js @@ -238,6 +238,8 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] initialize -> getExecutionContext -> Entering function."); } let date; + let maxRetries = 10; + let currentRetry = 0; date = new Date(thisObject.statusReport.runs[runIndex].lastExecution); thisObject.statusReport.runs[runIndex].lastExecution = bot.processDatetime; @@ -264,6 +266,15 @@ logger.write(MODULE_NAME, "[INFO] initialize -> getExecutionContext -> onFileReceived -> Content received = " + text); } + if(text === undefined){ // The File Sistem might be processing the request and delays can occur, in that case we will retry. + if(currentRetry < maxRetries){ + logger.write(MODULE_NAME, "[WARN] initialize -> getExecutionContext -> onFileReceived -> retry to get the context from storage " + currentRetry); + currentRetry++; + cloudStorage.getTextFile(filePath, fileName, onFileReceived); + return; + } + } + try { thisObject.executionContext = JSON.parse(text); @@ -284,14 +295,14 @@ /* It might happen that the file content is corrupt or it does not exist. The bot can not run without a Status Report, - since it is risky to ignore its own execution history. Execpt when the bot is running for the fist time in this mode, + since it is risky to ignore its own execution history. Except when the bot is running for the fist time in this mode, an execution context file with the right format is needed. */ - logger.write(MODULE_NAME, "[ERROR] initialize -> getExecutionContext -> onFileReceived -> Response from storage. -> Text = " + text); + logger.write(MODULE_NAME, "[ERROR] initialize -> getExecutionContext -> onFileReceived -> Response from storage. -> Text = " + text + ". Retry: "+currentRetry); logger.write(MODULE_NAME, "[ERROR] initialize -> getExecutionContext -> onFileReceived -> Bot cannot execute without the Execution Context. -> Err = " + err.message); - callBack(global.DEFAULT_RETRY_RESPONSE); + callBack(global.DEFAULT_FAIL_RESPONSE); } } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 058283b61..3ba1021c2 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,7 +1,7 @@ version: '3' services: node: - image: superalgos/clone-executor:1.0.3 + image: superalgos/clone-executor:1.0.4 build: context: . dockerfile: ./Dockerfile diff --git a/package.json b/package.json index c1dfc083b..7a034a5ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@superalgos/clone-executor", - "version": "1.0.0", + "version": "1.0.4", "description": "", "main": "Run.js", "scripts": {