Browse Source

Use the same database connection throughout the actor setup

fix-olivia-event-id
Thomas Eizinger 3 years ago
parent
commit
fa2ca990a1
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 13
      daemon/src/cleanup.rs
  2. 4
      daemon/src/maker.rs
  3. 4
      daemon/src/taker.rs

13
daemon/src/cleanup.rs

@ -1,13 +1,14 @@
use crate::db::{insert_new_cfd_state_by_order_id, load_all_cfds};
use crate::model::cfd::{Cfd, CfdState, CfdStateCommon};
use anyhow::Result;
use sqlx::SqlitePool;
use sqlx::pool::PoolConnection;
use sqlx::Sqlite;
use std::time::SystemTime;
pub async fn transition_non_continue_cfds_to_setup_failed(db: SqlitePool) -> Result<()> {
let mut conn = db.acquire().await?;
let cfds = load_all_cfds(&mut conn).await?;
pub async fn transition_non_continue_cfds_to_setup_failed(
conn: &mut PoolConnection<Sqlite>,
) -> Result<()> {
let cfds = load_all_cfds(conn).await?;
for cfd in cfds.iter().filter(|cfd| Cfd::is_cleanup(cfd)) {
insert_new_cfd_state_by_order_id(
@ -18,7 +19,7 @@ pub async fn transition_non_continue_cfds_to_setup_failed(db: SqlitePool) -> Res
},
info: format!("Was in state {} which cannot be continued.", cfd.state),
},
&mut conn,
conn,
)
.await?;
}

4
daemon/src/maker.rs

@ -150,10 +150,12 @@ async fn main() -> Result<()> {
Some(db) => (**db).clone(),
None => return Err(rocket),
};
let mut conn = db.acquire().await.unwrap();
cleanup::transition_non_continue_cfds_to_setup_failed(db.clone())
cleanup::transition_non_continue_cfds_to_setup_failed(&mut conn)
.await
.unwrap();
let cfds = load_all_cfds(&mut conn).await.unwrap();
let (maker_inc_connections_address, maker_inc_connections_context) =
xtra::Context::new(None);

4
daemon/src/taker.rs

@ -152,10 +152,12 @@ async fn main() -> Result<()> {
Some(db) => (**db).clone(),
None => return Err(rocket),
};
let mut conn = db.acquire().await.unwrap();
cleanup::transition_non_continue_cfds_to_setup_failed(db.clone())
cleanup::transition_non_continue_cfds_to_setup_failed(&mut conn)
.await
.unwrap();
let cfds = load_all_cfds(&mut conn).await.unwrap();
let send_to_maker = send_to_socket::Actor::new(write)
.create(None)

Loading…
Cancel
Save