[英]how frequently check mongoose connection status nodejs
I need to check the mongoose package connection string status dynamically after instance start, like npm start.我需要在实例启动后动态检查 mongoose 包连接字符串状态,例如 npm start。
I tried this method,这个方法我试过了
setInterval(function(){
if(mongoose.connection.readyState == 1){
mongoStatus = true;
}else{
mongoStatus = false;
}
}, 2000);
but i need mongoose predefined events?但我需要猫鼬预定义的事件?
NOTE: I am trying to create a custom circuit breaker for all services so that i need to check frequently the status注意:我正在尝试为所有服务创建一个自定义断路器,以便我需要经常检查状态
You can use the built-in Connection events in Mongoose.您可以使用 Mongoose 中的内置 连接事件。
mongoose.connection.on('error' | 'disconnecting' | 'disconnected' | 'close', event => {
mongoStatus = false // Or whatever you want to do
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.