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:
Tobias Reisinger 2024-03-28 01:23:49 +01:00
parent 6d31e1e2c9
commit 1d4e9efa15
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
5 changed files with 65 additions and 99 deletions
emgauwa-core

View file

@ -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"] }

View file

@ -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 {}:{}",