cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rkn...@apache.org
Subject cordova-medic git commit: CB-10405: Adding retry logic in check command
Date Wed, 03 Feb 2016 22:56:08 GMT
Repository: cordova-medic
Updated Branches:
  refs/heads/master 8dc0c0764 -> 50770495d


CB-10405: Adding retry logic in check command


Project: http://git-wip-us.apache.org/repos/asf/cordova-medic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-medic/commit/50770495
Tree: http://git-wip-us.apache.org/repos/asf/cordova-medic/tree/50770495
Diff: http://git-wip-us.apache.org/repos/asf/cordova-medic/diff/50770495

Branch: refs/heads/master
Commit: 50770495d86c46fcf3544ead6864657ef8b46213
Parents: 8dc0c07
Author: Sarangan Rajamanickam <sarajama@microsoft.com>
Authored: Fri Jan 29 15:47:54 2016 -0800
Committer: Sarangan Rajamanickam <sarajama@microsoft.com>
Committed: Wed Feb 3 14:52:52 2016 -0800

----------------------------------------------------------------------
 lib/testcheck.js     | 49 ++++++++++++++++++++++++++++-------------------
 medic/medic-check.js |  4 +++-
 2 files changed, 32 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/50770495/lib/testcheck.js
----------------------------------------------------------------------
diff --git a/lib/testcheck.js b/lib/testcheck.js
index 736a7f6..8948bfe 100644
--- a/lib/testcheck.js
+++ b/lib/testcheck.js
@@ -21,11 +21,30 @@
 
 "use strict";
 
-module.exports = function (sha, dbHost) {
+module.exports = function (sha, dbHost, maxnumberoftries, delay) {
 
     var http = require("http"),
         url = require("url"),
-        q = require("q");
+        q = require("q"),
+        util = require("./util");
+
+    function tryConnect(options, d, pendingnumberoftries, operation, successCallBack){
+        http.get(options, successCallBack)
+            .on("error", function(e){
+                if(pendingnumberoftries > 1){
+                    util.medicLog("Connection attempt to " + operation + " failed. Will try
after: " + delay + " milliseconds.");
+
+                    setTimeout(function (){
+                        tryConnect(options, d, pendingnumberoftries-1, operation, successCallBack);
+                    }, delay);
+                } else {
+                    util.medicLog("Failed to get document id after " + maxnumberoftries +
" attempts.");
+                    util.medicLog("Got error: " + e.message);
+                    d.reject(e);
+                }
+            });
+        return d.promise;
+    }
 
     function getDocumentIdBySha() {
         var options = {
@@ -33,10 +52,10 @@ module.exports = function (sha, dbHost) {
             port : url.parse(dbHost).port,
             path : "/mobilespec_results/_all_docs?start_key=\"" + sha + "\"&end_key=\""
+ sha + "~\"&limit=1"
         },
-            resultsDoc = "",
-            d = q.defer();
-
-        http.get(options, function (result) {
+        resultsDoc = "",
+        d = q.defer();
+        
+        return tryConnect(options, d, maxnumberoftries, "getDocumentIdBySha", function (result)
{
             result.on("data", function (chunk) {
                 resultsDoc += chunk.toString();
             });
@@ -48,12 +67,7 @@ module.exports = function (sha, dbHost) {
                     d.reject("There are no results for current test run in DB.");
                 }
             });
-        }).on("error", function (e) {
-            console.log("Got error: " + e.message);
-            d.reject(e);
         });
-
-        return d.promise;
     }
 
     function getTestResult(resultId) {
@@ -64,20 +78,15 @@ module.exports = function (sha, dbHost) {
         };
         var d = q.defer();
         var resultsJSON = "";
-
-        http.get(options, function (res) {
-            res.on("data", function (chunk) {
+        
+        return tryConnect(options, d, maxnumberoftries, "getTestResult", function (result)
{
+            result.on("data", function (chunk) {
                 resultsJSON += chunk;
             });
-            res.on("end", function () {
+            result.on("end", function () {
                 d.resolve(JSON.parse(resultsJSON));
             });
-        }).on("error", function (e) {
-            console.log("Got error: " + e.message);
-            d.reject(e);
         });
-
-        return d.promise;
     }
 
     return getDocumentIdBySha().then(getTestResult);

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/50770495/medic/medic-check.js
----------------------------------------------------------------------
diff --git a/medic/medic-check.js b/medic/medic-check.js
index 0c3d20d..46754e8 100644
--- a/medic/medic-check.js
+++ b/medic/medic-check.js
@@ -27,6 +27,8 @@ var optimist = require("optimist");
 
 var util      = require("../lib/util");
 var testcheck = require("../lib/testcheck");
+var MAX_NUMBER_OF_TRIES = 3;
+var WAIT_TIME_TO_RETRY_CONNECTION  = 15000; // in milliseconds
 
 // constants
 var INDENT = "    ";
@@ -49,7 +51,7 @@ function main() {
 
     console.log("Getting test results for " + buildId);
 
-    testcheck(buildId, couchdbURI).done(
+    testcheck(buildId, couchdbURI, MAX_NUMBER_OF_TRIES, WAIT_TIME_TO_RETRY_CONNECTION).done(
         function onFulfilled(testResults) {
 
             var numFailures = testResults.mobilespec.failures;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message