diff --git a/sslo_league/src/app_state.rs b/sslo_league/src/app_state.rs index 54012d5..6a6e2ec 100644 --- a/sslo_league/src/app_state.rs +++ b/sslo_league/src/app_state.rs @@ -43,7 +43,7 @@ pub struct LeagueAppState { pub database: Database, /// separate thread that handles reporting to lobby - pub lobby_mgr: LobbyMgr, + pub lobby_mgr: Option, // /// separate thread that manages all the server slots // pub slot_mgr: SlotMgr, @@ -104,15 +104,6 @@ impl LeagueAppState { }, }; - // setup lobby manager - let lobby_mgr = match LobbyMgr::new(shutdown_control.clone(), &config, league_logo_local.clone()) { - Ok(lobby_mgr) => lobby_mgr, - Err(e) => { - log::error!("Failed to start lobby manager!"); - return Err(e); - } - }; - // compile app state let mut app_state = Self { // slot_mgr, @@ -122,7 +113,7 @@ impl LeagueAppState { database, league_logo_http, league_logo_local, - lobby_mgr, + lobby_mgr: None, }; Ok(SsloAppState::new( @@ -131,6 +122,27 @@ impl LeagueAppState { )) } + /// This is must be called after new(), + /// intention is to allow the installer to execute before the background workers start + pub async fn start(&mut self) -> Result<(), SsloError> { + + // start lobby manager + if self.lobby_mgr.is_some() { + log::error!("lobby_mgr was already started!"); + return Err(SsloError::PropagateAlreadyLoggedError()); + } else { + self.lobby_mgr = match LobbyMgr::new(self.shutdown_control.clone(), &self.config, self.league_logo_local.clone()) { + Ok(lobby_mgr) => Some(lobby_mgr), + Err(e) => { + log::error!("Failed to start lobby manager!"); + return Err(e); + } + }; + } + + Ok(()) + } + /// Relate a path to the sslo database directory and return. /// When the given path already absolute, it is returned unchanged. @@ -163,7 +175,10 @@ impl LeagueAppState { } pub fn join(&self) { - self.lobby_mgr.join(); + if let Some(lobby_mgr) = self.lobby_mgr.as_ref() { + lobby_mgr.join(); + } + // self.slot_mgr.join(); } diff --git a/sslo_league/src/main.rs b/sslo_league/src/main.rs index b8614a2..06b0887 100644 --- a/sslo_league/src/main.rs +++ b/sslo_league/src/main.rs @@ -49,6 +49,8 @@ async fn main() -> Result<(), SsloError> { log::info!("installation successfully finished within: {}", formatter.format(duration_end - duration_start)); } + // startup everything + app_state.substate_mut().start().await?; // setup https routing let axum_router = http::create_router(app_state.clone());