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/src

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