Skip to content

Commit 0685f1a

Browse files
committed
refactor: [#1294] extract server-lib package
1 parent 3daf3f1 commit 0685f1a

35 files changed

+778
-67
lines changed

.github/workflows/deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
cargo publish -p bittorrent-udp-tracker-core
6363
cargo publish -p bittorrent-udp-tracker-protocol
6464
cargo publish -p torrust-axum-server
65+
cargo publish -p torrust-torrust-server-lib
6566
cargo publish -p torrust-tracker
6667
cargo publish -p torrust-tracker-api-client
6768
cargo publish -p torrust-tracker-api-core

Cargo.lock

+13-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
5454
figment = "0"
5555
futures = "0"
5656
futures-util = "0"
57-
http-body = "1"
5857
hyper = "1"
59-
hyper-util = { version = "0", features = ["http1", "http2", "tokio"] }
6058
lazy_static = "1"
6159
parking_lot = "0"
6260
percent-encoding = "2"
63-
pin-project-lite = "0"
6461
r2d2 = "0"
6562
r2d2_mysql = "25"
6663
r2d2_sqlite = { version = "0", features = ["bundled"] }
@@ -77,6 +74,7 @@ serde_with = { version = "3", features = ["json"] }
7774
thiserror = "2"
7875
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
7976
torrust-axum-server = { version = "3.0.0-develop", path = "packages/axum-server" }
77+
torrust-server-lib = { version = "3.0.0-develop", path = "packages/server-lib" }
8078
torrust-tracker-api-core = { version = "3.0.0-develop", path = "packages/tracker-api-core" }
8179
torrust-tracker-clock = { version = "3.0.0-develop", path = "packages/clock" }
8280
torrust-tracker-configuration = { version = "3.0.0-develop", path = "packages/configuration" }

packages/axum-server/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "A wrapper for the Axum server for Torrust HTTP servers to add tim
44
documentation.workspace = true
55
edition.workspace = true
66
homepage.workspace = true
7-
keywords = ["axum", "server", "torrust", "torrust", "wrapper"]
7+
keywords = ["axum", "server", "torrust", "wrapper"]
88
license.workspace = true
99
name = "torrust-axum-server"
1010
publish.workspace = true
@@ -21,6 +21,8 @@ hyper = "1"
2121
hyper-util = { version = "0", features = ["http1", "http2", "tokio"] }
2222
pin-project-lite = "0"
2323
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
24+
torrust-server-lib = { version = "3.0.0-develop", path = "../server-lib" }
2425
tower = { version = "0", features = ["timeout"] }
26+
tracing = "0"
2527

2628
[dev-dependencies]

packages/axum-server/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pub mod custom_axum_server;
1+
pub mod custom_axum_server;
2+
pub mod signals;

packages/axum-server/src/signals.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::time::Duration;
2+
3+
use tokio::time::sleep;
4+
use torrust_server_lib::signals::{shutdown_signal_with_message, Halted};
5+
use tracing::instrument;
6+
7+
#[instrument(skip(handle, rx_halt, message))]
8+
pub async fn graceful_shutdown(handle: axum_server::Handle, rx_halt: tokio::sync::oneshot::Receiver<Halted>, message: String) {
9+
shutdown_signal_with_message(rx_halt, message).await;
10+
11+
tracing::debug!("Sending graceful shutdown signal");
12+
handle.graceful_shutdown(Some(Duration::from_secs(90)));
13+
14+
println!("!! shuting down in 90 seconds !!");
15+
16+
loop {
17+
sleep(Duration::from_secs(1)).await;
18+
19+
tracing::info!("remaining alive connections: {}", handle.connection_count());
20+
}
21+
}

packages/server-lib/Cargo.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
authors.workspace = true
3+
description = "Common functionality used in all Torrust HTTP servers."
4+
documentation.workspace = true
5+
edition.workspace = true
6+
homepage.workspace = true
7+
keywords = ["lib", "server", "torrust"]
8+
license.workspace = true
9+
name = "torrust-server-lib"
10+
publish.workspace = true
11+
readme = "README.md"
12+
repository.workspace = true
13+
rust-version.workspace = true
14+
version.workspace = true
15+
16+
[dependencies]
17+
derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
18+
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
19+
tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] }
20+
tracing = "0"
21+
22+
[dev-dependencies]

0 commit comments

Comments
 (0)