mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-24 17:56:29 +00:00
healthchecks!
This commit is contained in:
16
src/pool.rs
16
src/pool.rs
@@ -43,8 +43,20 @@ impl ManageConnection for ServerPool {
|
||||
}
|
||||
|
||||
/// Determines if the connection is still connected to the database.
|
||||
async fn is_valid(&self, _conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
async fn is_valid(&self, conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error> {
|
||||
let server = &mut *conn;
|
||||
|
||||
// If this fails, the connection will be closed and another will be grabbed from the pool quietly :-).
|
||||
// Failover, step 1, complete.
|
||||
match tokio::time::timeout(
|
||||
tokio::time::Duration::from_millis(1000),
|
||||
server.query("SELECT 1"),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(_err) => Err(Error::ServerTimeout),
|
||||
}
|
||||
}
|
||||
|
||||
/// Synchronously determine if the connection is no longer usable, if possible.
|
||||
|
||||
Reference in New Issue
Block a user