Skip to content

Commit

Permalink
Update to ntex 0.4.13
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlospt committed Apr 4, 2024
1 parent 932d514 commit 18aeb05
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion services/shuttle-ntex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["shuttle-service", "ntex"]

[dependencies]
ntex = { version = "1.2.1", features = ["tokio"] }
ntex-rt = "0.4.12"
ntex-rt = "0.4.13"
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
num_cpus = "1.16.0"
shuttle-runtime = { path = "../../runtime", version = "0.43.0", default-features = false }
25 changes: 16 additions & 9 deletions services/shuttle-ntex/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![doc = include_str!("../README.md")]

use ntex::Service;
use std::net::SocketAddr;

/// A wrapper type for a closure that returns an [ntex::web::ServiceConfig] so we can implement
Expand All @@ -15,17 +14,25 @@ where
{
async fn bind(mut self, addr: SocketAddr) -> Result<(), shuttle_runtime::Error> {
// Start a worker for each cpu, but no more than 4.
let worker_count = num_cpus::get().min(4);
let cloned_addr = addr.clone();

let server =
ntex::web::HttpServer::new(move || ntex::web::App::new().configure(self.0.clone()))
.workers(worker_count)
.bind(addr)?
.run();
ntex::rt::System::new("main")
.run_local(async move {
let worker_count = num_cpus::get().min(4);

server.await.map_err(shuttle_runtime::CustomError::new)?;
let server =
ntex::web::HttpServer::new(move || ntex::web::App::new().configure(self.0.clone()))
.workers(worker_count)
.bind(cloned_addr)?
.run();

Ok(())
server.await.map_err(shuttle_runtime::CustomError::new)?;

Ok::<(), shuttle_runtime::Error>(())
})
.await?;

Ok::<(), shuttle_runtime::Error>(())
}
}

Expand Down

0 comments on commit 18aeb05

Please sign in to comment.