Skip to content

Commit

Permalink
Merge pull request #16 from graphprotocol/mde/retry-failed-request
Browse files Browse the repository at this point in the history
chore: add a retry option for ipfs request
  • Loading branch information
Maikol authored Apr 22, 2024
2 parents 569a743 + e8491d5 commit 97459ba
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 97459ba

Please sign in to comment.