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

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 1e90bb2..510a0a2 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 108973f..9aa7d95 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -22,7 +22,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;
@@ -468,7 +469,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);
@@ -476,8 +477,8 @@ module.exports = function(logger, triggerDB, redisClient) {
                             .catch(err => {
                                 logger.error(method, err);
                             });
-                            }
-                        });
+                        }
+                    });
                     resolve();
                 })
                 .catch(err => {


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to