grpc-ts-health-check
Advanced tools
Comparing version 2.0.0-beta.0 to 2.0.0-beta.1
{ | ||
"name": "grpc-ts-health-check", | ||
"version": "2.0.0-beta.0", | ||
"version": "2.0.0-beta.1", | ||
"description": "An implementation of gRPC health checks, written in typescript.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -49,3 +49,2 @@ # gRPC Health Check | ||
const grpcHealthCheck = new GrpcHealthCheck(healthCheckStatusMap); | ||
grpcHealthCheck.watch(serviceName); | ||
server.addService(HealthService, grpcHealthCheck); | ||
@@ -57,4 +56,21 @@ | ||
// Check the health status | ||
const healthClient = new HealthClient(`${host}:${port}`, grpc.credentials.createInsecure()); | ||
const request = new HealthCheckRequest(); | ||
request.setService(serviceName); | ||
healthClient.check(request, (error: Error | null, response: HealthCheckResponse) => { | ||
if (error) { | ||
AppLogger.logger.error('Contact Service: Health Check Failed', error); | ||
} else { | ||
AppLogger.logger.debug(`Contact Service: Health Check Status: ${response.getStatus()}`); | ||
} | ||
}); | ||
// Watch health status changes | ||
const healthStream = healthClient.watch(request); | ||
healthStream.on('data', (response: HealthCheckResponse) => { | ||
AppLogger.logger.debug(`Contact Service: Health Check Status: ${response.getStatus()}`); | ||
}); | ||
return server; | ||
} | ||
``` |
@@ -51,7 +51,6 @@ "use strict"; | ||
this.watchStatusMap[service] = updatedStatus; | ||
let lastStatus = -1; | ||
if (!this.watchErrorMap[service]) { | ||
console.log('Next Tick'); | ||
const callback = () => { | ||
lastStatus = this.statusMap[service]; | ||
const interval = setInterval(() => { | ||
if (!this.watchErrorMap[service]) { | ||
console.log('Next Tick'); | ||
const lastStatus = this.statusMap[service] || -1; | ||
if (lastStatus !== updatedStatus) { | ||
@@ -66,10 +65,10 @@ console.log('Sending Status: ' + updatedStatus); | ||
} | ||
}; | ||
process.nextTick(callback); | ||
} | ||
else { | ||
call.end(this.watchErrorMap[service]); | ||
} | ||
} | ||
else { | ||
clearInterval(interval); | ||
call.end(this.watchErrorMap[service]); | ||
} | ||
}, 1000); | ||
} | ||
} | ||
exports.GrpcHealthCheck = GrpcHealthCheck; |
27620
75
509