mirror of https://github.com/rwf2/Rocket.git
Update 'deadpool' to 0.10.
Also updates: * 'deadpool-postgres' to 0.12 * 'deadpool-redis' to 0.14
This commit is contained in:
parent
9544715103
commit
3bcdd076c3
|
@ -23,8 +23,8 @@ sqlx_postgres = ["sqlx", "sqlx/postgres"]
|
||||||
sqlx_sqlite = ["sqlx", "sqlx/sqlite"]
|
sqlx_sqlite = ["sqlx", "sqlx/sqlite"]
|
||||||
sqlx_macros = ["sqlx/macros"]
|
sqlx_macros = ["sqlx/macros"]
|
||||||
# diesel features
|
# diesel features
|
||||||
diesel_postgres = ["diesel-async/postgres", "diesel-async/deadpool", "diesel", "deadpool"]
|
diesel_postgres = ["diesel-async/postgres", "diesel-async/deadpool", "diesel", "deadpool_09"]
|
||||||
diesel_mysql = ["diesel-async/mysql", "diesel-async/deadpool", "diesel", "deadpool"]
|
diesel_mysql = ["diesel-async/mysql", "diesel-async/deadpool", "diesel", "deadpool_09"]
|
||||||
# implicit features: mongodb
|
# implicit features: mongodb
|
||||||
|
|
||||||
[dependencies.rocket]
|
[dependencies.rocket]
|
||||||
|
@ -36,20 +36,27 @@ default-features = false
|
||||||
path = "../codegen"
|
path = "../codegen"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies.deadpool]
|
[dependencies.deadpool_09]
|
||||||
|
package = "deadpool"
|
||||||
version = "0.9"
|
version = "0.9"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["rt_tokio_1", "managed"]
|
features = ["rt_tokio_1", "managed"]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.deadpool-postgres]
|
[dependencies.deadpool-postgres]
|
||||||
version = "0.10"
|
version = "0.12"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["rt_tokio_1"]
|
features = ["rt_tokio_1"]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
|
[dependencies.deadpool]
|
||||||
|
version = "0.10"
|
||||||
|
default-features = false
|
||||||
|
features = ["rt_tokio_1", "managed"]
|
||||||
|
optional = true
|
||||||
|
|
||||||
[dependencies.deadpool-redis]
|
[dependencies.deadpool-redis]
|
||||||
version = "0.12"
|
version = "0.14"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["rt_tokio_1"]
|
features = ["rt_tokio_1"]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
|
@ -107,8 +107,8 @@
|
||||||
//!
|
//!
|
||||||
//! | Database | Feature | [`Pool`] Type | [`Connection`] Deref |
|
//! | Database | Feature | [`Pool`] Type | [`Connection`] Deref |
|
||||||
//! |----------|-----------------------------|-----------------------------|--------------------------------------|
|
//! |----------|-----------------------------|-----------------------------|--------------------------------------|
|
||||||
//! | Postgres | `deadpool_postgres` (v0.10) | [`deadpool_postgres::Pool`] | [`deadpool_postgres::ClientWrapper`] |
|
//! | Postgres | `deadpool_postgres` (v0.12) | [`deadpool_postgres::Pool`] | [`deadpool_postgres::ClientWrapper`] |
|
||||||
//! | Redis | `deadpool_redis` (v0.11) | [`deadpool_redis::Pool`] | [`deadpool_redis::Connection`] |
|
//! | Redis | `deadpool_redis` (v0.14) | [`deadpool_redis::Pool`] | [`deadpool_redis::Connection`] |
|
||||||
//!
|
//!
|
||||||
//! On shutdown, new connections are denied. Shutdown _does not_ wait for
|
//! On shutdown, new connections are denied. Shutdown _does not_ wait for
|
||||||
//! connections to be returned.
|
//! connections to be returned.
|
||||||
|
|
|
@ -156,9 +156,7 @@ pub trait Pool: Sized + Send + Sync + 'static {
|
||||||
mod deadpool_postgres {
|
mod deadpool_postgres {
|
||||||
use deadpool::{managed::{Manager, Pool, PoolError, Object, BuildError}, Runtime};
|
use deadpool::{managed::{Manager, Pool, PoolError, Object, BuildError}, Runtime};
|
||||||
use super::{Duration, Error, Config, Figment};
|
use super::{Duration, Error, Config, Figment};
|
||||||
|
use rocket::Either;
|
||||||
#[cfg(any(feature = "diesel_postgres", feature = "diesel_mysql"))]
|
|
||||||
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
|
||||||
|
|
||||||
pub trait DeadManager: Manager + Sized + Send + Sync + 'static {
|
pub trait DeadManager: Manager + Sized + Send + Sync + 'static {
|
||||||
fn new(config: &Config) -> Result<Self, Self::Error>;
|
fn new(config: &Config) -> Result<Self, Self::Error>;
|
||||||
|
@ -178,6 +176,50 @@ mod deadpool_postgres {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rocket::async_trait]
|
||||||
|
impl<M: DeadManager, C: From<Object<M>>> crate::Pool for Pool<M, C>
|
||||||
|
where M::Type: Send, C: Send + Sync + 'static, M::Error: std::error::Error
|
||||||
|
{
|
||||||
|
type Error = Error<Either<M::Error, BuildError>, PoolError<M::Error>>;
|
||||||
|
|
||||||
|
type Connection = C;
|
||||||
|
|
||||||
|
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
|
||||||
|
let config: Config = figment.extract()?;
|
||||||
|
let manager = M::new(&config).map_err(|e| Error::Init(Either::Left(e)))?;
|
||||||
|
|
||||||
|
Pool::builder(manager)
|
||||||
|
.max_size(config.max_connections)
|
||||||
|
.wait_timeout(Some(Duration::from_secs(config.connect_timeout)))
|
||||||
|
.create_timeout(Some(Duration::from_secs(config.connect_timeout)))
|
||||||
|
.recycle_timeout(config.idle_timeout.map(Duration::from_secs))
|
||||||
|
.runtime(Runtime::Tokio1)
|
||||||
|
.build()
|
||||||
|
.map_err(|e| Error::Init(Either::Right(e)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get(&self) -> Result<Self::Connection, Self::Error> {
|
||||||
|
self.get().await.map_err(Error::Get)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn close(&self) {
|
||||||
|
<Pool<M, C>>::close(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove when new release of diesel-async with deadpool 0.10 is out.
|
||||||
|
#[cfg(all(feature = "deadpool_09", any(feature = "diesel_postgres", feature = "diesel_mysql")))]
|
||||||
|
mod deadpool_old {
|
||||||
|
use deadpool_09::{managed::{Manager, Pool, PoolError, Object, BuildError}, Runtime};
|
||||||
|
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
||||||
|
|
||||||
|
use super::{Duration, Error, Config, Figment};
|
||||||
|
|
||||||
|
pub trait DeadManager: Manager + Sized + Send + Sync + 'static {
|
||||||
|
fn new(config: &Config) -> Result<Self, Self::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "diesel_postgres")]
|
#[cfg(feature = "diesel_postgres")]
|
||||||
impl DeadManager for AsyncDieselConnectionManager<diesel_async::AsyncPgConnection> {
|
impl DeadManager for AsyncDieselConnectionManager<diesel_async::AsyncPgConnection> {
|
||||||
fn new(config: &Config) -> Result<Self, Self::Error> {
|
fn new(config: &Config) -> Result<Self, Self::Error> {
|
||||||
|
|
Loading…
Reference in New Issue