From 0ce45a6cac4049a1e585e9eca2daa0321362f0bd Mon Sep 17 00:00:00 2001 From: "Archambault, Samuel" Date: Tue, 21 Mar 2017 11:34:57 -0400 Subject: [PATCH 1/2] Retrying connection to consul to avoid purge if consul is not available --- lib/consul/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/consul/index.js b/lib/consul/index.js index b1fbdad..b2a3ee6 100644 --- a/lib/consul/index.js +++ b/lib/consul/index.js @@ -410,6 +410,16 @@ var process_records = function(branch, records, cb) { exports.getLastProcessedRef = function(branch, cb) { var key_name = create_key_name(branch, branch.name + '.ref', true); consul.kv.get({'key': key_name, token: token}, function(err, item) { + if(err) { + logger.warn('Cannot connect to consul to get the last processed reference id. Retrying...'); + setTimeout( + function() { + exports.getLastProcessedRef(branch,cb); + },5000 + ); + // end this "thread" + return; + } /* istanbul ignore if */ if (err) return cb(err); cb(null, item === undefined ? item : item.Value); From a0179e72471b5c13068ab2d94237337f1944c10d Mon Sep 17 00:00:00 2001 From: "Archambault, Samuel" Date: Tue, 21 Mar 2017 12:23:20 -0400 Subject: [PATCH 2/2] removing err check that is not reachable. --- lib/consul/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/consul/index.js b/lib/consul/index.js index b2a3ee6..f1a824e 100644 --- a/lib/consul/index.js +++ b/lib/consul/index.js @@ -411,7 +411,7 @@ exports.getLastProcessedRef = function(branch, cb) { var key_name = create_key_name(branch, branch.name + '.ref', true); consul.kv.get({'key': key_name, token: token}, function(err, item) { if(err) { - logger.warn('Cannot connect to consul to get the last processed reference id. Retrying...'); + logger.warn('Cannot connect to consul to get the last processed reference id. Retrying!...'); setTimeout( function() { exports.getLastProcessedRef(branch,cb); @@ -420,8 +420,6 @@ exports.getLastProcessedRef = function(branch, cb) { // end this "thread" return; } - /* istanbul ignore if */ - if (err) return cb(err); cb(null, item === undefined ? item : item.Value); }); };