From 3d66ca2472e2cccbde59fa8805e25460a7d2cbd3 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sun, 3 Mar 2024 22:39:28 +0100 Subject: [PATCH] Add more debugging and fix some --- Cargo.lock | Bin 65731 -> 65731 bytes emgauwa-controller/src/app_state.rs | 1 + emgauwa-core/src/app_state.rs | 1 + .../handlers/v1/ws/controllers/handlers.rs | 2 ++ .../src/handlers/v1/ws/controllers/mod.rs | 19 +++++++++--------- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09b3924a1d10bcbb910ea59ff115a1c15c7c083c..c43f40a05e38d060ed3ad8850d0605a05a0e03a2 100644 GIT binary patch delta 40 ycmV+@0N4M+fds>W1hBe7lbJy>ll4NX0b`TR!XT5%LMxNYK^l|&LLajmM5w%l(GuVQ delta 30 ocmV+(0O9|`fds>W1hBe718HJold3~Flk7sOlhwi)v$sPGz1FY}NdN!< diff --git a/emgauwa-controller/src/app_state.rs b/emgauwa-controller/src/app_state.rs index aa9553c..75811ba 100644 --- a/emgauwa-controller/src/app_state.rs +++ b/emgauwa-controller/src/app_state.rs @@ -47,6 +47,7 @@ impl Handler for AppState { type Result = Result<(), EmgauwaError>; fn handle(&mut self, _msg: Reload, _ctx: &mut Self::Context) -> Self::Result { + log::debug!("Reloading controller"); let mut pool_conn = block_on(self.pool.acquire())?; self.this.reload(&mut pool_conn)?; diff --git a/emgauwa-core/src/app_state.rs b/emgauwa-core/src/app_state.rs index ab97265..4fd2765 100644 --- a/emgauwa-core/src/app_state.rs +++ b/emgauwa-core/src/app_state.rs @@ -70,6 +70,7 @@ impl Handler for AppState { type Result = Result<(), EmgauwaError>; fn handle(&mut self, msg: ConnectController, _ctx: &mut Self::Context) -> Self::Result { + log::debug!("Connecting controller: {}", msg.controller.c.uid); self.connected_controllers .insert(msg.controller.c.uid.clone(), (msg.controller, msg.address)); diff --git a/emgauwa-core/src/handlers/v1/ws/controllers/handlers.rs b/emgauwa-core/src/handlers/v1/ws/controllers/handlers.rs index 6148c5e..3d67920 100644 --- a/emgauwa-core/src/handlers/v1/ws/controllers/handlers.rs +++ b/emgauwa-core/src/handlers/v1/ws/controllers/handlers.rs @@ -31,6 +31,7 @@ impl ControllerWs { block_on(controller_db.update_active(conn, true))?; for relay in &controller.relays { + log::debug!("Registering relay: {}", relay.r.name); let (new_relay, created) = block_on(DbRelay::get_by_controller_and_num_or_create( conn, &controller_db, @@ -69,6 +70,7 @@ impl ControllerWs { controller, }))??; + log::debug!("Done registering controller"); Ok(()) } } diff --git a/emgauwa-core/src/handlers/v1/ws/controllers/mod.rs b/emgauwa-core/src/handlers/v1/ws/controllers/mod.rs index 445e408..a205b78 100644 --- a/emgauwa-core/src/handlers/v1/ws/controllers/mod.rs +++ b/emgauwa-core/src/handlers/v1/ws/controllers/mod.rs @@ -51,10 +51,16 @@ impl ControllerWs { conn: &mut PoolConnection, ctx: &mut ::Context, action: ControllerWsAction, - ) -> Result<(), EmgauwaError> { - match action { + ) { + let action_res = match action { ControllerWsAction::Register(controller) => self.handle_register(conn, ctx, controller), _ => Ok(()), + }; + if let Err(e) = action_res { + log::error!("Error handling action: {:?}", e); + ctx.text( + serde_json::to_string(&e).unwrap_or(format!("Error in handling action: {:?}", e)), + ); } } @@ -121,14 +127,7 @@ impl StreamHandler> for ControllerWs { } Message::Text(text) => match serde_json::from_str(&text) { Ok(action) => { - let action_res = self.handle_action(&mut pool_conn, ctx, action); - if let Err(e) = action_res { - log::error!("Error handling action: {:?}", e); - ctx.text( - serde_json::to_string(&e) - .unwrap_or(format!("Error in handling action: {:?}", e)), - ); - } + self.handle_action(&mut pool_conn, ctx, action); } Err(e) => { log::error!("Error deserializing action: {:?}", e);