Add sql transactions
This commit is contained in:
parent
455ca50695
commit
9823511b62
9 changed files with 171 additions and 138 deletions
|
|
@ -63,9 +63,10 @@ impl AppState {
|
|||
}
|
||||
|
||||
fn get_relays(&self) -> Result<Vec<Relay>, EmgauwaError> {
|
||||
let mut pool_conn = block_on(self.pool.acquire())?;
|
||||
let db_controllers = block_on(DbController::get_all(&mut pool_conn))?;
|
||||
let mut controllers: Vec<Controller> = convert_db_list(&mut pool_conn, db_controllers)?;
|
||||
let mut tx = block_on(self.pool.begin())?;
|
||||
let db_controllers = block_on(DbController::get_all(&mut tx))?;
|
||||
let mut controllers: Vec<Controller> = convert_db_list(&mut tx, db_controllers)?;
|
||||
block_on(tx.commit())?;
|
||||
|
||||
self.connected_controllers
|
||||
.iter()
|
||||
|
|
@ -113,11 +114,11 @@ impl Handler<DisconnectController> for AppState {
|
|||
type Result = Result<(), EmgauwaError>;
|
||||
|
||||
fn handle(&mut self, msg: DisconnectController, _ctx: &mut Self::Context) -> Self::Result {
|
||||
let mut pool_conn = block_on(self.pool.acquire())?;
|
||||
let mut tx = block_on(self.pool.begin())?;
|
||||
|
||||
if let Some((controller, address)) = self.connected_controllers.remove(&msg.controller_uid)
|
||||
{
|
||||
if let Err(err) = block_on(controller.c.update_active(&mut pool_conn, false)) {
|
||||
if let Err(err) = block_on(controller.c.update_active(&mut tx, false)) {
|
||||
log::error!(
|
||||
"Failed to mark controller {} as inactive: {:?}",
|
||||
controller.c.uid,
|
||||
|
|
@ -128,6 +129,7 @@ impl Handler<DisconnectController> for AppState {
|
|||
//block_on(address.send(ControllerWsAction::Disconnect))??;
|
||||
address.do_send(ControllerWsAction::Disconnect);
|
||||
}
|
||||
block_on(tx.commit())?;
|
||||
self.notify_relay_clients();
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue