Skip to content

Commit

Permalink
buck2_execute(materializer): create MaterializerDispatchableHttpRetry…
Browse files Browse the repository at this point in the history
…Warning

Summary: NFC. Wired up, but won't take effect yet.

Signed-off-by: Austin Seipp <[email protected]>
Change-Id: I6d061db6956e2133e33a74d79bb2f583
  • Loading branch information
thoughtpolice committed Jul 13, 2023
1 parent 45cf9a1 commit 5973949
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/buck2_execute/src/materialize/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use buck2_common::http::HttpClient;
use buck2_core::fs::fs_util;
use buck2_core::fs::project::ProjectRoot;
use buck2_core::fs::project_rel_path::ProjectRelativePath;
use buck2_data::NoopDispatchableHttpRetryWarning;
use buck2_data::DispatchableHttpRetryWarning;
use buck2_data::HttpRequestRetried;
use bytes::Bytes;
use digest::DynDigest;
use dupe::Dupe;
Expand Down Expand Up @@ -100,10 +101,36 @@ impl AsHttpError for HttpDownloadError {
}
}

struct MaterializerDispatchableHttpRetryWarning {}

impl MaterializerDispatchableHttpRetryWarning {
fn new() -> Self {
Self {}
}
}

impl DispatchableHttpRetryWarning for MaterializerDispatchableHttpRetryWarning {
fn dispatch(&self, dur: &Duration, _retries: usize, url: &str) {
let event: HttpRequestRetried = HttpRequestRetried {
backoff_duration_secs: dur.as_secs(),
url: url.to_owned(),
};

match buck2_events::dispatch::get_dispatcher_opt() {
Some(dispatcher) => {
dispatcher.instant_event(event.clone());
}
None => {
tracing::warn!("Failed to dispatch HttpRequestRetried event: {:?}", event)
}
}
}
}

pub async fn http_head(client: &dyn HttpClient, url: &str) -> anyhow::Result<Response<()>> {
let response = http_retry(
url,
NoopDispatchableHttpRetryWarning::new(),
MaterializerDispatchableHttpRetryWarning::new(),
|| async {
client
.head(url)
Expand Down Expand Up @@ -132,7 +159,7 @@ pub async fn http_download(

Ok(http_retry(
url,
NoopDispatchableHttpRetryWarning::new(),
MaterializerDispatchableHttpRetryWarning::new(),
|| async {
let file = fs_util::create_file(&abs_path).map_err(HttpDownloadError::IoError)?;

Expand Down

0 comments on commit 5973949

Please sign in to comment.