Skip to content

Commit 97459ba

Browse files
authored
Merge pull request #16 from graphprotocol/mde/retry-failed-request
chore: add a retry option for ipfs request
2 parents 569a743 + e8491d5 commit 97459ba

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

availability-oracle/src/ipfs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,24 @@ impl Ipfs for IpfsImpl {
8686
return Result::Ok(cached_bytes);
8787
}
8888

89-
let res = self.call("cat", cid).await;
89+
async fn call_with_retry(
90+
ipfs: &IpfsImpl,
91+
cid: Cid,
92+
retries: usize,
93+
) -> Result<reqwest::Response, IpfsError> {
94+
let mut last_err = None;
95+
for _ in 0..=retries {
96+
match ipfs.call("cat", cid).await {
97+
Ok(res) => return Ok(res),
98+
Err(e) => {
99+
last_err = Some(e);
100+
}
101+
}
102+
}
103+
Err(last_err.unwrap())
104+
}
105+
106+
let res = call_with_retry(self, cid, 1).await;
90107
METRICS.ipfs_requests_total.inc();
91108
let final_bytes = res?.bytes().map_err(|e| IpfsError::Other(e.into())).await?;
92109

0 commit comments

Comments
 (0)