Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder authored Sep 6, 2023
2 parents e39c6eb + be36014 commit e091ed0
Show file tree
Hide file tree
Showing 65 changed files with 550 additions and 407 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye, bookworm
ARG VARIANT="bookworm"
FROM mcr.microsoft.com/devcontainers/rust:1-${VARIANT}

# Include lld linker to improve build times either by using environment variable
# RUSTFLAGS="-C link-arg=-fuse-ld=lld" or with Cargo's configuration file (i.e see .cargo/config.toml).
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install clang lld \
&& apt-get autoremove -y && apt-get clean -y
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/rust-postgres
{
"name": "Deadpool",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"ms-azuretools.vscode-docker"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5432],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
68 changes: 68 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: "3.8"

volumes:
postgres-data:
redis-data:
redis-cluster-data:
rabbitmq-data:


services:
app:
build:
context: .
dockerfile: Dockerfile
args:
# Use the VARIANT arg to pick a Debian OS version: buster, bullseye, bookworm
# Use bullseye when on local on arm64/Apple Silicon.
VARIANT: bookworm
env_file:
# Ensure that the variables in .env match the same variables in devcontainer.json
- .env
# Security Opt and cap_add for C++ based debuggers to work.
# See `runArgs`: https://github.com/Microsoft/vscode-docs/blob/main/docs/remote/devcontainerjson-reference.md
# security_opt:
# - seccomp:unconfined
# cap_add:
# - SYS_PTRACE

volumes:
- ..:/workspace:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
#network_mode: service:postgres

# Uncomment the next line to use a non-root user for all processes.
# user: vscode

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

postgres:
image: postgres:15-alpine
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
env_file:
- postgres.env

redis:
image: redis:7.2-alpine
restart: unless-stopped
volumes:
- redis-data:/data

redis-cluster:
image: grokzen/redis-cluster:7.0.10
restart: unless-stopped
volumes:
- redis-cluster-data:/redis-data

rabbitmq:
image: rabbitmq:3.12-alpine
env_file:
- rabbitmq.env
volumes:
- rabbitmq-data:/var/lib/rabbitmq
3 changes: 3 additions & 0 deletions .devcontainer/postgres.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_PASSWORD=deadpool
POSTGRES_USER=deadpool
POSTGRES_DB=deadpool
3 changes: 3 additions & 0 deletions .devcontainer/rabbitmq.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RABBITMQ_DEFAULT_USER=deadpool
RABBITMQ_DEFAULT_PASS=deadpool
RABBITMQ_DEFAULT_VHOST=deadpool
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
image: postgres:15.3-alpine
ports:
- 5432:5432
env:
Expand All @@ -189,16 +189,15 @@ jobs:
--health-timeout 5s
--health-retries 5
redis:
image: redis
image: redis:7.0-alpine
ports:
- 6379:6379
redis-cluster:
image: grokzen/redis-cluster
image: grokzen/redis-cluster:7.0.10
ports:
- 7000-7005:7000-7005

rabbitmq:
image: rabbitmq:3.8 # 3.9 and above doesn't support env vars
image: rabbitmq:3.11-alpine
ports:
- 5672:5672
env:
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

## v0.10.0 (unreleased)

- Remove unreachable enum variant `BuildError::Backend`
- Split `Status.available` into `available` and `waiting`.
- Add `QueueMode` configuration option for choosing between
a `FIFO` (default) and `LIFO` queue.
- Remove `HookError::Continue` and `HookError::Abort` variants
replacing it with the contents of `HookErrorCause`. Returning
a `HookError` from a `post_create` hook causes the `Pool::get`
operation to fail while returning it from a `pre_recycle` or
`post_recycle` hook the operation continues.
- Add `metrics` argument to `Manager::recycle` method.

## v0.9.5

- Fix bug causing the pool to exceed its `max_size` in the
Expand Down
19 changes: 12 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "deadpool"
version = "0.9.5"
version = "0.10.0"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
description = "Dead simple async pool"
keywords = ["async", "database", "pool"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/bikeshedder/deadpool"
readme = "README.md"

Expand All @@ -23,7 +23,7 @@ rt_async-std_1 = ["deadpool-runtime/async-std_1"]

[dependencies]
num_cpus = "1.11.1"
retain_mut ="0.1.6"
retain_mut = "0.1.6"
# `managed` feature
async-trait = { version = "0.1.17", optional = true }
# `serde` feature
Expand All @@ -38,9 +38,14 @@ tokio = { version = "1.0", features = ["sync"] }
[dev-dependencies]
async-std = { version = "1.0", features = ["attributes"] }
config = { version = "0.13", features = ["json"] }
criterion = { version = "0.3.4", features = ["html_reports", "async_tokio"] }
itertools = "0.10.3"
tokio = { version = "1.5.0", features = ["macros", "rt", "rt-multi-thread", "time"] }
criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
itertools = "0.11.0"
tokio = { version = "1.5.0", features = [
"macros",
"rt",
"rt-multi-thread",
"time",
] }

[[bench]]
name = "managed"
Expand All @@ -62,5 +67,5 @@ members = [
"runtime",
"sqlite",
"sync",
"examples/*"
"examples/*",
]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl managed::Manager for Manager {
Ok(Computer {})
}

async fn recycle(&self, _: &mut Computer) -> managed::RecycleResult<Error> {
async fn recycle(&self, _: &mut Computer, _: &managed::Metrics) -> managed::RecycleResult<Error> {
Ok(())
}
}
Expand Down Expand Up @@ -99,6 +99,7 @@ Backend | Crate | Latest Version |
[async-memcached](https://crates.io/crates/async-memcached) | [deadpool-memcached](https://crates.io/crates/deadpool-memcached) | [![Latest Version](https://img.shields.io/crates/v/deadpool-memcached.svg)](https://crates.io/crates/deadpool-memcached) |
[rusqlite](https://crates.io/crates/rusqlite) | [deadpool-sqlite](https://crates.io/crates/deadpool-sqlite) | [![Latest Version](https://img.shields.io/crates/v/deadpool-sqlite.svg)](https://crates.io/crates/deadpool-sqlite) |
[diesel](https://crates.io/crates/diesel) | [deadpool-diesel](https://crates.io/crates/deadpool-diesel) | [![Latest Version](https://img.shields.io/crates/v/deadpool-diesel.svg)](https://crates.io/crates/deadpool-diesel) |
[tiberius](https://crates.io/crates/tiberius) | [deadpool-tiberius](https://crates.io/crates/deadpool-tiberius) | [![Latest Version](https://img.shields.io/crates/v/deadpool-tiberius.svg)](https://crates.io/crates/deadpool-tiberius) |
[r2d2](https://crates.io/crates/r2d2) | [deadpool-r2d2](https://crates.io/crates/deadpool-r2d2) | [![Latest Version](https://img.shields.io/crates/v/deadpool-r2d2.svg)](https://crates.io/crates/deadpool-r2d2) |
[rbatis](https://crates.io/crates/rbatis) | [rbatis](https://crates.io/crates/rbatis) | [![Latest Version](https://img.shields.io/crates/v/rbatis.svg)](https://crates.io/crates/rbatis) |

Expand Down
7 changes: 6 additions & 1 deletion benches/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{convert::TryInto, fmt::Display};

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};

use deadpool::managed::Metrics;
use tokio::task::JoinHandle;

//const ITERATIONS: usize = 1_048_576;
Expand Down Expand Up @@ -50,7 +51,11 @@ impl deadpool::managed::Manager for Manager {
async fn create(&self) -> Result<Self::Type, Self::Error> {
Ok(())
}
async fn recycle(&self, _: &mut Self::Type) -> deadpool::managed::RecycleResult<Self::Error> {
async fn recycle(
&self,
_: &mut Self::Type,
_: &Metrics,
) -> deadpool::managed::RecycleResult<Self::Error> {
Ok(())
}
}
Expand Down
6 changes: 5 additions & 1 deletion diesel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Change Log

## v0.5.0 (unreleased)

- Update `deadpool` dependency to version `0.10`

## v0.4.1

* Fix error handling when recycling connections

## v0.4.0

* Update Diesel to 2.0.0
* Update `diesel` dependency to version `2.0.0`

## v0.3.1

Expand Down
10 changes: 6 additions & 4 deletions diesel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "deadpool-diesel"
version = "0.4.1"
version = "0.5.0"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
description = "Dead simple async pool for diesel"
keywords = ["async", "database", "pool", "diesel"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/bikeshedder/deadpool"
readme = "README.md"

Expand All @@ -24,8 +24,10 @@ rt_async-std_1 = ["deadpool/rt_async-std_1"]
serde = ["deadpool/serde"]

[dependencies]
deadpool = { path = "../", version = "0.9.1", default-features = false, features = ["managed"] }
deadpool-sync = { path = "../sync", version = "0.1.0" }
deadpool = { path = "../", version = "0.10.0", default-features = false, features = [
"managed",
] }
deadpool-sync = { path = "../sync", version = "0.1.1" }
diesel = { version = "2.0.0", default-features = false }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions diesel/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt, marker::PhantomData};

use deadpool::{
async_trait,
managed::{self, RecycleError, RecycleResult},
managed::{self, Metrics, RecycleError, RecycleResult},
Runtime,
};
use deadpool_sync::SyncWrapper;
Expand Down Expand Up @@ -65,7 +65,7 @@ where
.await
}

async fn recycle(&self, obj: &mut Self::Type) -> RecycleResult<Self::Error> {
async fn recycle(&self, obj: &mut Self::Type, _: &Metrics) -> RecycleResult<Self::Error> {
if obj.is_mutex_poisoned() {
return Err(RecycleError::StaticMessage(
"Mutex is poisoned. Connection is considered unusable.",
Expand Down
23 changes: 23 additions & 0 deletions examples/diesel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "example-diesel"
version = "0.0.0"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
publish = false

[dependencies]
actix-web = "4.0.1"
anyhow = "1.0.65"
config = "0.13"
deadpool = { version = "0.10", path = "../.." }
deadpool-diesel = { version = "0.5.0", path = "../../diesel", features = [
"postgres",
] }
diesel = { version = "2.0.0", features = ["postgres", "chrono"] }
dotenvy = "0.15"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
tokio-postgres = { version = "0.7", features = ["with-uuid-1"] }
uuid = { version = "1", features = ["serde"] }
36 changes: 36 additions & 0 deletions examples/diesel/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use deadpool_diesel::postgres::{BuildError, Manager, Pool};

use deadpool_diesel::Runtime;

use std::env;
use thiserror::Error;

#[derive(Error, Debug)]

pub enum PoolError {
#[error("unable to load .env file")]
Env(dotenvy::Error),

#[error("missing DATABASE_URL")]
DatabaseURL,

#[error("unable to build pool")]
PoolBuildError(BuildError),
}

pub fn set_up_pool() -> Result<Pool, PoolError> {
dotenvy::dotenv().map_err(PoolError::Env)?;

let database_url = env::var("DATABASE_URL").map_err(|_| PoolError::DatabaseURL)?;

let manager = Manager::new(database_url, Runtime::Tokio1);

let pool = Pool::builder(manager)
.max_size(8)
.build()
.map_err(PoolError::PoolBuildError)?;

Ok(pool)
}

pub fn main() {}
Loading

0 comments on commit e091ed0

Please sign in to comment.