Skip to content

Commit

Permalink
feat: 🎸 grpc connection check
Browse files Browse the repository at this point in the history
  • Loading branch information
hcfw007 committed Jun 20, 2022
1 parent 5b9b1a4 commit 3a6b373
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client/grpc-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class GrpcManager extends EventEmitter {
protected _client? : puppet.PuppetClient
get client () : puppet.PuppetClient {
if (!this._client) {
this.emit('error', 'NO CLIENT')
throw new Error('NO CLIENT')
}
return this._client
Expand Down
17 changes: 17 additions & 0 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class PuppetService extends PUPPET.Puppet {
protected _grpcManager?: GrpcManager
get grpcManager (): GrpcManager {
if (!this._grpcManager) {
this.emit('error', 'no grpc manager')
throw new Error('no grpc manager')
}
return this._grpcManager
Expand Down Expand Up @@ -173,6 +174,9 @@ class PuppetService extends PUPPET.Puppet {
await grpcManager.start()
log.verbose('PuppetService', 'start() starting grpc manager... done')

log.verbose('PuppetService', 'start healthCheck')
this.startHealthCheck()

/**
* Ducks management
*/
Expand Down Expand Up @@ -201,6 +205,8 @@ class PuppetService extends PUPPET.Puppet {
}

log.verbose('PuppetService', 'onStop() ... done')
log.verbose('PuppetService', 'stop healthCheck')
this.stopHealthCheck()
}

protected hookPayloadStore (): void {
Expand Down Expand Up @@ -1984,6 +1990,17 @@ class PuppetService extends PUPPET.Puppet {
}
}

healthCheckInterval?: NodeJS.Timer
startHealthCheck () {
this.healthCheckInterval = setInterval(() => {
this.ding('healthCheck')
}, 60 * 1000)
}

stopHealthCheck () {
clearInterval(this.healthCheckInterval!)
}

}

export {
Expand Down

0 comments on commit 3a6b373

Please sign in to comment.