Skip to content

Commit

Permalink
tx insert error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 19, 2024
1 parent 4764076 commit ec1b6f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/load_exchange_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ pub async fn swap_batch(
ignored_count += ig;
}
Err(e) => {
let secs = 10;
error!("skipping batch, could not insert: {:?}", e);
warn!("waiting 5 secs before retrying connection");
thread::sleep(Duration::from_secs(5));
warn!("waiting {} secs before retrying connection", secs);
thread::sleep(Duration::from_secs(secs));
}
};
}
Expand Down
23 changes: 16 additions & 7 deletions src/load_tx_cypher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Context, Result};
use log::info;
use log::{error, info, warn};
use neo4rs::{query, Graph};
use std::fmt::Display;
use std::{fmt::Display, thread, time::Duration};

use crate::{cypher_templates::write_batch_tx_string, queue, table_structs::WarehouseTxMaster};

Expand Down Expand Up @@ -48,6 +48,7 @@ impl BatchTxReturn {
}
}

// TODO: code duplication with exchange order loading.
pub async fn tx_batch(
txs: &[WarehouseTxMaster],
pool: &Graph,
Expand Down Expand Up @@ -79,11 +80,19 @@ pub async fn tx_batch(
}
info!("...loading to db");

let batch = impl_batch_tx_insert(pool, c).await?;

all_results.increment(&batch);
queue::update_task(pool, archive_id, true, i).await?;
info!("...success");
match impl_batch_tx_insert(pool, c).await {
Ok(batch) => {
all_results.increment(&batch);
queue::update_task(pool, archive_id, true, i).await?;
info!("...success");
}
Err(e) => {
let secs = 10;
error!("skipping batch, could not insert: {:?}", e);
warn!("waiting {} secs before retrying connection", secs);
thread::sleep(Duration::from_secs(secs));
}
};
}

Ok(all_results)
Expand Down

0 comments on commit ec1b6f0

Please sign in to comment.