name servers & dont leave open servers with bad state

This commit is contained in:
Lev Kokotov
2022-02-03 17:06:19 -08:00
parent abb71b6c4d
commit 6deb7b1162
6 changed files with 182 additions and 27 deletions

View File

@@ -1,9 +1,8 @@
use async_trait::async_trait;
use bb8::{ManageConnection, PooledConnection};
use crate::server::Server;
use crate::errors::Error;
use crate::server::Server;
pub struct ServerPool {
host: String,
@@ -30,10 +29,17 @@ impl ManageConnection for ServerPool {
type Connection = Server;
type Error = Error;
/// Attempts to create a new connection.
/// Attempts to create a new connection.
async fn connect(&self) -> Result<Self::Connection, Self::Error> {
println!(">> Getting connetion from pool");
Ok(Server::startup(&self.host, &self.port, &self.user, &self.password, &self.database).await?)
Ok(Server::startup(
&self.host,
&self.port,
&self.user,
&self.password,
&self.database,
)
.await?)
}
/// Determines if the connection is still connected to the database.
@@ -42,7 +48,7 @@ impl ManageConnection for ServerPool {
}
/// Synchronously determine if the connection is no longer usable, if possible.
fn has_broken(&self, _conn: &mut Self::Connection) -> bool {
false
fn has_broken(&self, conn: &mut Self::Connection) -> bool {
conn.is_bad()
}
}
}