Skip to content

Commit

Permalink
buck2_common(http): wire up DispatchableHttpRetryWarning trait to fire
Browse files Browse the repository at this point in the history
Summary: This switches both the materializer and the manifold client to use the
new interface, all at once.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: I6d061db6956e2133e33a74d79bb2f583
  • Loading branch information
thoughtpolice committed Jul 13, 2023
1 parent 5973949 commit 53db4b4
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/buck2_common/src/http/retries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub trait AsHttpError {
}

pub async fn http_retry<Exec, F, T, E, R>(
_url: &str,
_dispatch_retry_warning: R,
url: &str,
dispatch_retry_warning: R,
exec: Exec,
mut intervals: Vec<Duration>,
) -> Result<T, E>
Expand All @@ -61,6 +61,7 @@ where
intervals.insert(0, Duration::from_secs(0));
let mut backoff = intervals.into_iter().peekable();

let mut retries = 0;
while let Some(duration) = backoff.next() {
tokio::time::sleep(duration).await;

Expand All @@ -70,12 +71,9 @@ where

if let Some(http_error) = http_error {
if http_error.is_retryable() {
retries += 1;
if let Some(b) = backoff.peek() {
tracing::warn!(
"Retrying a HTTP error after {} seconds: {:#}",
b.as_secs(),
http_error
);
dispatch_retry_warning.dispatch(&b, retries, url);
continue;
}
}
Expand Down

0 comments on commit 53db4b4

Please sign in to comment.