Skip to content

Commit

Permalink
Retry getting block date and price
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Lykov committed Jan 23, 2024
1 parent a773f1e commit c0ad717
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ use {
path::PathBuf,
process::exit,
str::FromStr,
thread::sleep,
time::Duration,
},
sys::{
app_version,
Expand Down Expand Up @@ -125,6 +127,25 @@ async fn get_block_date_and_price(
))
}

async fn retry_get_block_date_and_price(
rpc_client: &RpcClient,
slot: Slot,
token: MaybeToken,
) -> Result<(NaiveDate, Decimal), Box<dyn std::error::Error>> {
const NUM_RETRIES: usize = 20;
for _ in 1..NUM_RETRIES {
let date_price = get_block_date_and_price(rpc_client, slot, token).await;
if date_price.is_ok() {
println!("Got block date and price");
return date_price;
}
println!("Retry get_block_date_and_price");
//emprically observed cool down period is ~14s
sleep(Duration::from_secs(5));
}
get_block_date_and_price(rpc_client, slot, token).await
}

fn add_exchange_deposit_address_to_db(
db: &mut Db,
exchange: Exchange,
Expand Down Expand Up @@ -3439,8 +3460,7 @@ async fn process_account_sync(

let slot = inflation_reward.effective_slot;
let (when, price) =
get_block_date_and_price(rpc_client, slot, account.token).await?;

retry_get_block_date_and_price(rpc_client, slot, account.token).await?;
let lot = Lot {
lot_number: db.next_lot_number(),
acquisition: LotAcquistion::new(
Expand Down

0 comments on commit c0ad717

Please sign in to comment.