Skip to content

Commit

Permalink
chore: add a retry option for ipfs request
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Apr 16, 2024
1 parent 569a743 commit 643ba5f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion availability-oracle/src/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,24 @@ impl Ipfs for IpfsImpl {
return Result::Ok(cached_bytes);
}

let res = self.call("cat", cid).await;
async fn call_with_retry(
ipfs: &IpfsImpl,
cid: Cid,
retries: usize,
) -> Result<reqwest::Response, IpfsError> {
let mut last_err = None;
for _ in 0..=retries {
match ipfs.call("cat", cid).await {
Ok(res) => return Ok(res),
Err(e) => {
last_err = Some(e);
},
}
}
Err(last_err.unwrap())
}

let res = call_with_retry(self, cid, 1).await;
METRICS.ipfs_requests_total.inc();
let final_bytes = res?.bytes().map_err(|e| IpfsError::Other(e.into())).await?;

Expand Down

0 comments on commit 643ba5f

Please sign in to comment.