Skip to content

Commit ef7fe55

Browse files
committed
buck2_execute(materializer): create MaterializerDispatchableHttpRetryWarning
Summary: NFC. Wired up, but won't take effect yet. Signed-off-by: Austin Seipp <[email protected]> Change-Id: I6d061db6956e2133e33a74d79bb2f583
1 parent cf0ff12 commit ef7fe55

File tree

1 file changed

+30
-3
lines changed
  • app/buck2_execute/src/materialize

1 file changed

+30
-3
lines changed

app/buck2_execute/src/materialize/http.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ use buck2_common::file_ops::TrackedFileDigest;
2020
use buck2_common::http::counting_client::CountingHttpClient;
2121
use buck2_common::http::retries::http_retry;
2222
use buck2_common::http::retries::AsHttpError;
23+
use buck2_common::http::retries::DispatchableHttpRetryWarning;
2324
use buck2_common::http::retries::HttpError;
24-
use buck2_common::http::retries::NoopDispatchableHttpRetryWarning;
2525
use buck2_common::http::HttpClient;
2626
use buck2_core::fs::fs_util;
2727
use buck2_core::fs::project::ProjectRoot;
2828
use buck2_core::fs::project_rel_path::ProjectRelativePath;
29+
use buck2_data::HttpRequestRetried;
2930
use bytes::Bytes;
3031
use digest::DynDigest;
3132
use dupe::Dupe;
@@ -100,10 +101,36 @@ impl AsHttpError for HttpDownloadError {
100101
}
101102
}
102103

104+
struct MaterializerDispatchableHttpRetryWarning {}
105+
106+
impl MaterializerDispatchableHttpRetryWarning {
107+
fn new() -> Self {
108+
Self {}
109+
}
110+
}
111+
112+
impl DispatchableHttpRetryWarning for MaterializerDispatchableHttpRetryWarning {
113+
fn dispatch(&self, dur: &Duration, _retries: usize, url: &str) {
114+
let event: HttpRequestRetried = HttpRequestRetried {
115+
backoff_duration_secs: dur.as_secs(),
116+
url: url.to_owned(),
117+
};
118+
119+
match buck2_events::dispatch::get_dispatcher_opt() {
120+
Some(dispatcher) => {
121+
dispatcher.instant_event(event);
122+
}
123+
None => {
124+
tracing::warn!("Failed to dispatch HttpRequestRetried event: {:?}", event)
125+
}
126+
}
127+
}
128+
}
129+
103130
pub async fn http_head(client: &dyn HttpClient, url: &str) -> anyhow::Result<Response<()>> {
104131
let response = http_retry(
105132
url,
106-
NoopDispatchableHttpRetryWarning::new(),
133+
MaterializerDispatchableHttpRetryWarning::new(),
107134
|| async {
108135
client
109136
.head(url)
@@ -132,7 +159,7 @@ pub async fn http_download(
132159

133160
Ok(http_retry(
134161
url,
135-
NoopDispatchableHttpRetryWarning::new(),
162+
MaterializerDispatchableHttpRetryWarning::new(),
136163
|| async {
137164
let file = fs_util::create_file(&abs_path).map_err(HttpDownloadError::IoError)?;
138165

0 commit comments

Comments
 (0)