Skip to content

Commit

Permalink
Ensure microservice monitor functions when running in discoverable mo…
Browse files Browse the repository at this point in the history
…de and ZK isn't running
  • Loading branch information
ph0bos committed Aug 5, 2015
1 parent c626b73 commit 3af45d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions lib/monitors/microservice-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var Promise = require('bluebird').Promise;
var async = require('async');
var zoologist = require('../zoologist');

var CHECK_INTERVAL_MS = 2000;

/**
* VitalSigns Health Monitor for a Microservice.
*
Expand All @@ -28,22 +30,27 @@ var svcHealth = null;
* Peridically check the health of the microservice.
*/
var interval = setInterval(function() {
checkMicroserviceHealth()
.then(function (health) {
var check = checkMicroserviceHealth()

if (check) {
check.then(function (health) {
svcHealth = health;
});
}, 5000);
}
}, CHECK_INTERVAL_MS);

/**
* Invoke health check.
*/
function checkMicroserviceHealth(callback) {
function checkMicroserviceHealth() {
var resolver = Promise.pending();

if (!zoologist.getServiceDiscovery() || !zoologist.getServiceDiscovery().getData()) {
return resolver.resolve({
resolver.resolve({
status: (zoologist.getClient().getClient().getState().name === 'SYNC_CONNECTED') ? 'UP' : 'DOWN'
});

return resolver.promise;
}

var health = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-microservice-starter",
"version": "0.5.1",
"version": "0.5.2",
"description": "An express-based Node.js API bootstrapping module for microservices.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3af45d2

Please sign in to comment.