Skip to content

Commit

Permalink
do not wait if we're done retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenyang007 committed Mar 10, 2024
1 parent 15a98c6 commit be6740a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 45 deletions.
23 changes: 8 additions & 15 deletions rust/processor/src/models/object_models/v2_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ impl Object {
match Self::get_current_object(
conn,
&resource.address,
txn_version,
query_retries,
query_retry_delay_ms,
)
Expand Down Expand Up @@ -173,13 +172,12 @@ impl Object {
pub async fn get_current_object(
conn: &mut PgPoolConnection<'_>,
object_address: &str,
transaction_version: i64,
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<CurrentObject> {
let mut retries = 0;
while retries < query_retries {
retries += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match CurrentObjectQuery::get_by_address(object_address, conn).await {
Ok(res) => {
return Ok(CurrentObject {
Expand All @@ -192,16 +190,11 @@ impl Object {
is_deleted: res.is_deleted,
});
},
Err(e) => {
warn!(
transaction_version,
error = ?e,
object_address,
retry_ms = query_retry_delay_ms,
"Failed to get object from current_objects table.",
);
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
Err(_) => {
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand Down
24 changes: 14 additions & 10 deletions rust/processor/src/models/stake_models/current_delegated_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,18 @@ impl CurrentDelegatedVoter {
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<String> {
let mut retried = 0;
while retried < query_retries {
retried += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match CurrentDelegatedVoterQuery::get_by_table_handle(conn, table_handle).await {
Ok(current_delegated_voter_query_result) => {
return Ok(current_delegated_voter_query_result.delegation_pool_address);
},
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand All @@ -215,9 +217,9 @@ impl CurrentDelegatedVoter {
query_retries: u32,
query_retry_delay_ms: u64,
) -> bool {
let mut retried = 0;
while retried < query_retries {
retried += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match CurrentDelegatedVoterQuery::get_by_pk(
conn,
delegator_address,
Expand All @@ -227,8 +229,10 @@ impl CurrentDelegatedVoter {
{
Ok(_) => return true,
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand Down
12 changes: 7 additions & 5 deletions rust/processor/src/models/stake_models/delegator_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,18 @@ impl CurrentDelegatorBalance {
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<String> {
let mut retried = 0;
while retried < query_retries {
retried += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match CurrentDelegatorBalanceQuery::get_by_inactive_share_handle(conn, table_handle)
.await
{
Ok(current_delegator_balance) => return Ok(current_delegator_balance.pool_address),
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand Down
12 changes: 7 additions & 5 deletions rust/processor/src/models/token_models/collection_datas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ impl CollectionData {
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<String> {
let mut retried = 0;
while retried < query_retries {
retried += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match CurrentCollectionDataQuery::get_by_table_handle(conn, table_handle).await {
Ok(current_collection_data) => return Ok(current_collection_data.creator_address),
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand Down
12 changes: 7 additions & 5 deletions rust/processor/src/models/token_v2_models/v2_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,16 @@ impl CollectionV2 {
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<String> {
let mut retried = 0;
while retried < query_retries {
retried += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match Self::get_by_table_handle(conn, table_handle).await {
Ok(creator) => return Ok(creator),
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand Down
12 changes: 7 additions & 5 deletions rust/processor/src/models/token_v2_models/v2_token_ownerships.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,9 @@ impl CurrentTokenOwnershipV2Query {
query_retries: u32,
query_retry_delay_ms: u64,
) -> anyhow::Result<NFTOwnershipV2> {
let mut retried = 0;
while retried < query_retries {
retried += 1;
let mut tried = 0;
while tried < query_retries {
tried += 1;
match Self::get_latest_owned_nft_by_token_data_id_impl(conn, token_data_id).await {
Ok(inner) => {
return Ok(NFTOwnershipV2 {
Expand All @@ -631,8 +631,10 @@ impl CurrentTokenOwnershipV2Query {
});
},
Err(_) => {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
if tried < query_retries {
tokio::time::sleep(std::time::Duration::from_millis(query_retry_delay_ms))
.await;
}
},
}
}
Expand Down

0 comments on commit be6740a

Please sign in to comment.