You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2018/05/09 18:18:49 UTC

[incubator-openwhisk-package-alarms] branch master updated: do not assume env var HOST_INDEX begins with 'host' (#150)

This is an automated email from the ASF dual-hosted git repository.

dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-alarms.git


The following commit(s) were added to refs/heads/master by this push:
     new 1886bd4  do not assume env var HOST_INDEX begins with 'host' (#150)
1886bd4 is described below

commit 1886bd49ed877af0e8f901d6d3e60b5bc17e9f1a
Author: Jason Peterson <ja...@us.ibm.com>
AuthorDate: Wed May 9 14:18:47 2018 -0400

    do not assume env var HOST_INDEX begins with 'host' (#150)
---
 provider/lib/active.js | 2 +-
 provider/lib/utils.js  | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

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 => {

-- 
To stop receiving notification emails like this one, please contact
dubeejw@apache.org.