pub struct PGRobustNotifier<F> { /* private fields */ }Expand description
Wraps a PGNotifier and reconnects upon connection loss.
This struct keeps a callback that can be use to spawn new connections to postgres.
It’s called upon each time a connection is lost. All the heavy lifting is actually
done by the PGNotifier struct.
Implementations§
Source§impl<F, S, T> PGRobustNotifier<F>where
F: AsyncFn() -> PGResult<(Client, Connection<S, T>)>,
S: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
T: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
impl<F, S, T> PGRobustNotifier<F>where
F: AsyncFn() -> PGResult<(Client, Connection<S, T>)>,
S: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
T: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
pub async fn new(connect: F) -> PGResult<Self>
Sourcepub async fn client(&mut self) -> PGResult<&PGClient>
pub async fn client(&mut self) -> PGResult<&PGClient>
Returns the underlying postgres client. If the connection has been closed then it is reconnected.
Note that Client::is_closed is not reliable unless we have a high frequency TPC keepalive,
over which we have no control. So we actually attempt a real query each time. Taking inspiration
from sqlx, we issue a comment request so that it does not show up in logs. The possibility of
the connection being closed right after the ping still exist but should be handled by the
caller.
The pool will keep trying to reconnect until it succeeds using exponential backoff with additional jitter.