Add more debugging and fix some
This commit is contained in:
		
							parent
							
								
									b2ff632e64
								
							
						
					
					
						commit
						3d66ca2472
					
				
					 5 changed files with 14 additions and 11 deletions
				
			
		
							
								
								
									
										2
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -729,7 +729,6 @@ dependencies = [
 | 
				
			||||||
 "chrono",
 | 
					 "chrono",
 | 
				
			||||||
 "emgauwa-lib",
 | 
					 "emgauwa-lib",
 | 
				
			||||||
 "futures",
 | 
					 "futures",
 | 
				
			||||||
 "libc",
 | 
					 | 
				
			||||||
 "log",
 | 
					 "log",
 | 
				
			||||||
 "serde",
 | 
					 "serde",
 | 
				
			||||||
 "serde_derive",
 | 
					 "serde_derive",
 | 
				
			||||||
| 
						 | 
					@ -748,6 +747,7 @@ dependencies = [
 | 
				
			||||||
 "chrono",
 | 
					 "chrono",
 | 
				
			||||||
 "config",
 | 
					 "config",
 | 
				
			||||||
 "futures",
 | 
					 "futures",
 | 
				
			||||||
 | 
					 "libc",
 | 
				
			||||||
 "libsqlite3-sys",
 | 
					 "libsqlite3-sys",
 | 
				
			||||||
 "log",
 | 
					 "log",
 | 
				
			||||||
 "serde",
 | 
					 "serde",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,6 +47,7 @@ impl Handler<Reload> for AppState {
 | 
				
			||||||
	type Result = Result<(), EmgauwaError>;
 | 
						type Result = Result<(), EmgauwaError>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fn handle(&mut self, _msg: Reload, _ctx: &mut Self::Context) -> Self::Result {
 | 
						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())?;
 | 
							let mut pool_conn = block_on(self.pool.acquire())?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		self.this.reload(&mut pool_conn)?;
 | 
							self.this.reload(&mut pool_conn)?;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,6 +70,7 @@ impl Handler<ConnectController> for AppState {
 | 
				
			||||||
	type Result = Result<(), EmgauwaError>;
 | 
						type Result = Result<(), EmgauwaError>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fn handle(&mut self, msg: ConnectController, _ctx: &mut Self::Context) -> Self::Result {
 | 
						fn handle(&mut self, msg: ConnectController, _ctx: &mut Self::Context) -> Self::Result {
 | 
				
			||||||
 | 
							log::debug!("Connecting controller: {}", msg.controller.c.uid);
 | 
				
			||||||
		self.connected_controllers
 | 
							self.connected_controllers
 | 
				
			||||||
			.insert(msg.controller.c.uid.clone(), (msg.controller, msg.address));
 | 
								.insert(msg.controller.c.uid.clone(), (msg.controller, msg.address));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,7 @@ impl ControllerWs {
 | 
				
			||||||
		block_on(controller_db.update_active(conn, true))?;
 | 
							block_on(controller_db.update_active(conn, true))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for relay in &controller.relays {
 | 
							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(
 | 
								let (new_relay, created) = block_on(DbRelay::get_by_controller_and_num_or_create(
 | 
				
			||||||
				conn,
 | 
									conn,
 | 
				
			||||||
				&controller_db,
 | 
									&controller_db,
 | 
				
			||||||
| 
						 | 
					@ -69,6 +70,7 @@ impl ControllerWs {
 | 
				
			||||||
			controller,
 | 
								controller,
 | 
				
			||||||
		}))??;
 | 
							}))??;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							log::debug!("Done registering controller");
 | 
				
			||||||
		Ok(())
 | 
							Ok(())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,10 +51,16 @@ impl ControllerWs {
 | 
				
			||||||
		conn: &mut PoolConnection<Sqlite>,
 | 
							conn: &mut PoolConnection<Sqlite>,
 | 
				
			||||||
		ctx: &mut <ControllerWs as Actor>::Context,
 | 
							ctx: &mut <ControllerWs as Actor>::Context,
 | 
				
			||||||
		action: ControllerWsAction,
 | 
							action: ControllerWsAction,
 | 
				
			||||||
	) -> Result<(), EmgauwaError> {
 | 
						) {
 | 
				
			||||||
		match action {
 | 
							let action_res = match action {
 | 
				
			||||||
			ControllerWsAction::Register(controller) => self.handle_register(conn, ctx, controller),
 | 
								ControllerWsAction::Register(controller) => self.handle_register(conn, ctx, controller),
 | 
				
			||||||
			_ => Ok(()),
 | 
								_ => 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<Result<Message, ProtocolError>> for ControllerWs {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			Message::Text(text) => match serde_json::from_str(&text) {
 | 
								Message::Text(text) => match serde_json::from_str(&text) {
 | 
				
			||||||
				Ok(action) => {
 | 
									Ok(action) => {
 | 
				
			||||||
					let action_res = self.handle_action(&mut pool_conn, ctx, action);
 | 
										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)),
 | 
					 | 
				
			||||||
						);
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				Err(e) => {
 | 
									Err(e) => {
 | 
				
			||||||
					log::error!("Error deserializing action: {:?}", e);
 | 
										log::error!("Error deserializing action: {:?}", e);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue