mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(redis_interface): remove the Drop implementation on RedisConnectionPool (#1786)
This commit is contained in:
@ -33,7 +33,6 @@ pub use self::{commands::*, types::*};
|
|||||||
pub struct RedisConnectionPool {
|
pub struct RedisConnectionPool {
|
||||||
pub pool: fred::pool::RedisPool,
|
pub pool: fred::pool::RedisPool,
|
||||||
config: RedisConfig,
|
config: RedisConfig,
|
||||||
join_handles: Vec<fred::types::ConnectHandle>,
|
|
||||||
pub subscriber: SubscriberClient,
|
pub subscriber: SubscriberClient,
|
||||||
pub publisher: RedisClient,
|
pub publisher: RedisClient,
|
||||||
pub is_redis_available: Arc<atomic::AtomicBool>,
|
pub is_redis_available: Arc<atomic::AtomicBool>,
|
||||||
@ -136,7 +135,6 @@ impl RedisConnectionPool {
|
|||||||
.into_report()
|
.into_report()
|
||||||
.change_context(errors::RedisError::RedisConnectionError)?;
|
.change_context(errors::RedisError::RedisConnectionError)?;
|
||||||
|
|
||||||
let join_handles = pool.connect();
|
|
||||||
pool.wait_for_connect()
|
pool.wait_for_connect()
|
||||||
.await
|
.await
|
||||||
.into_report()
|
.into_report()
|
||||||
@ -147,37 +145,12 @@ impl RedisConnectionPool {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
pool,
|
pool,
|
||||||
config,
|
config,
|
||||||
join_handles,
|
|
||||||
is_redis_available: Arc::new(atomic::AtomicBool::new(true)),
|
is_redis_available: Arc::new(atomic::AtomicBool::new(true)),
|
||||||
subscriber,
|
subscriber,
|
||||||
publisher,
|
publisher,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn close_connections(&mut self) {
|
|
||||||
self.pool.quit_pool().await;
|
|
||||||
|
|
||||||
self.publisher
|
|
||||||
.quit()
|
|
||||||
.await
|
|
||||||
.map_err(|err| logger::error!(redis_quit_err=?err))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
self.subscriber
|
|
||||||
.quit()
|
|
||||||
.await
|
|
||||||
.map_err(|err| logger::error!(redis_quit_err=?err))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
for handle in self.join_handles.drain(..) {
|
|
||||||
match handle.await {
|
|
||||||
Ok(Ok(_)) => (),
|
|
||||||
Ok(Err(error)) => logger::error!(%error),
|
|
||||||
Err(error) => logger::error!(%error),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn on_error(&self, tx: tokio::sync::oneshot::Sender<()>) {
|
pub async fn on_error(&self, tx: tokio::sync::oneshot::Sender<()>) {
|
||||||
while let Ok(redis_error) = self.pool.on_error().recv().await {
|
while let Ok(redis_error) = self.pool.on_error().recv().await {
|
||||||
logger::error!(?redis_error, "Redis protocol or connection error");
|
logger::error!(?redis_error, "Redis protocol or connection error");
|
||||||
@ -194,14 +167,6 @@ impl RedisConnectionPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RedisConnectionPool {
|
|
||||||
// safety: panics when invoked without a current tokio runtime
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let rt = tokio::runtime::Handle::current();
|
|
||||||
rt.block_on(self.close_connections())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RedisConfig {
|
struct RedisConfig {
|
||||||
default_ttl: u32,
|
default_ttl: u32,
|
||||||
default_stream_read_count: u64,
|
default_stream_read_count: u64,
|
||||||
|
|||||||
@ -10,7 +10,6 @@ use crate::{configs::settings::Database, errors};
|
|||||||
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
|
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
|
||||||
|
|
||||||
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
|
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
|
||||||
pub type RedisPool = std::sync::Arc<redis_interface::RedisConnectionPool>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct TestTransaction;
|
struct TestTransaction;
|
||||||
|
|||||||
Reference in New Issue
Block a user