Browse Source
Use the same database connection throughout the actor setup
fix-olivia-event-id
Thomas Eizinger
3 years ago
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
3 changed files with
13 additions and
8 deletions
-
daemon/src/cleanup.rs
-
daemon/src/maker.rs
-
daemon/src/taker.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?; |
|
|
|
} |
|
|
|
|
|
@ -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); |
|
|
|
|
|
@ -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) |
|
|
|