Try to fix the threading
Add explicit tokio::spawn in controller Add an arbiter for the app_state in core
This commit is contained in:
parent
6d31e1e2c9
commit
1d4e9efa15
5 changed files with 21 additions and 10 deletions
BIN
Cargo.lock
generated
BIN
Cargo.lock
generated
Binary file not shown.
|
@ -10,9 +10,9 @@ emgauwa-lib = { path = "../emgauwa-lib" }
|
|||
actix = "0.13"
|
||||
|
||||
tokio = { version = "1.34", features = ["io-std", "macros", "rt-multi-thread"] }
|
||||
tokio-tungstenite = "0.20"
|
||||
tokio-tungstenite = "0.21"
|
||||
|
||||
simple_logger = "4.2"
|
||||
simple_logger = "4.3"
|
||||
log = "0.4"
|
||||
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
|
|
@ -112,10 +112,10 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
);
|
||||
|
||||
|
||||
tokio::select! {
|
||||
_ = run_relays_loop(app_state.clone()) => {},
|
||||
_ = run_ws_loop(pool.clone(), app_state.clone(), url) => {},
|
||||
}
|
||||
let _ = tokio::join!(
|
||||
tokio::spawn(run_relays_loop(app_state.clone())),
|
||||
tokio::spawn(run_ws_loop(pool.clone(), app_state.clone(), url)),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ emgauwa-lib = { path = "../emgauwa-lib" }
|
|||
actix = "0.13"
|
||||
actix-web = "4.4"
|
||||
actix-web-actors = "4.2"
|
||||
actix-cors = "0.6"
|
||||
actix-cors = "0.7"
|
||||
|
||||
log = "0.4"
|
||||
|
||||
|
@ -23,4 +23,5 @@ serde_derive = "1.0"
|
|||
|
||||
sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio", "macros", "chrono"] }
|
||||
|
||||
futures = "0.3.29"
|
||||
futures = "0.3"
|
||||
tokio = { version = "1.36", features = ["rt", "rt-multi-thread"] }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::net::TcpListener;
|
||||
|
||||
use actix::Actor;
|
||||
use actix::{Actor, Arbiter};
|
||||
use actix_cors::Cors;
|
||||
use actix_web::middleware::TrailingSlash;
|
||||
use actix_web::{middleware, web, App, HttpServer};
|
||||
|
@ -32,7 +32,17 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
.map_err(EmgauwaError::from)?;
|
||||
conn.close().await.map_err(EmgauwaError::from)?;
|
||||
|
||||
let app_state = AppState::new(pool.clone()).start();
|
||||
let app_state_arbiter = Arbiter::with_tokio_rt(|| {
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(2)
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
});
|
||||
let app_state_pool = pool.clone();
|
||||
let app_state = Actor::start_in_arbiter(&app_state_arbiter.handle(), move |_| {
|
||||
AppState::new(app_state_pool.clone())
|
||||
});
|
||||
|
||||
log::info!(
|
||||
"Starting server on {}:{}",
|
||||
|
|
Loading…
Reference in a new issue