dubee closed pull request #174: do not assume env var HOST_INDEX begins with 
'host'
URL: https://github.com/apache/incubator-openwhisk-package-cloudant/pull/174
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/provider/lib/active.js b/provider/lib/active.js
index cbc5017..980473b 100644
--- a/provider/lib/active.js
+++ b/provider/lib/active.js
@@ -24,7 +24,7 @@ module.exports = function(logger, utils) {
                 return;
             }
 
-            var redundantHost = utils.host === 'host0' ? 'host1' : 'host0';
+            var redundantHost = utils.host === `${utils.hostPrefix}0` ? 
`${utils.hostPrefix}1` : `${utils.hostPrefix}0`;
             var activeHost = query === 'true' ? utils.host : redundantHost;
             if (utils.activeHost !== activeHost) {
                 if (utils.redisClient) {
diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index 1256d59..808beb4 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -16,7 +16,8 @@ module.exports = function(logger, triggerDB, redisClient) {
     this.routerHost = process.env.ROUTER_HOST || 'localhost';
     this.worker = process.env.WORKER || 'worker0';
     this.host = process.env.HOST_INDEX || 'host0';
-    this.activeHost = 'host0'; //default value on init (will be updated for 
existing redis)
+    this.hostPrefix = this.host.replace(/\d+$/, '');
+    this.activeHost = `${this.hostPrefix}0`; //default value on init (will be 
updated for existing redis)
     this.db = triggerDB;
     this.redisClient = redisClient;
     this.redisKey = redisKeyPrefix + '_' + this.worker;
@@ -462,7 +463,7 @@ module.exports = function(logger, triggerDB, redisClient) {
                 .then(() => {
                     process.on('SIGTERM', function onSigterm() {
                         if (self.activeHost === self.host) {
-                            var redundantHost = self.host === 'host0' ? 
'host1' : 'host0';
+                            var redundantHost = self.host === 
`${self.hostPrefix}0` ? `${self.hostPrefix}1` : `${self.hostPrefix}0`;
                             self.redisClient.hsetAsync(self.redisKey, 
self.redisField, redundantHost)
                             .then(() => {
                                 self.redisClient.publish(self.redisKey, 
redundantHost);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to