diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-07-29 22:44:06 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2024-07-29 22:44:06 +0200 |
commit | d14edab92446017e9e47bfba86974a933db2a366 (patch) | |
tree | 3e9a5ce75859f77a1e2c0e66ed8377dfee88c2d8 | |
parent | fs-tracer: update file contents across multiple writes (diff) | |
download | fs-tracer-d14edab92446017e9e47bfba86974a933db2a366.tar.gz fs-tracer-d14edab92446017e9e47bfba86974a933db2a366.tar.bz2 fs-tracer-d14edab92446017e9e47bfba86974a933db2a366.zip |
fs-tracer: add retries when sending requests to backend
-rw-r--r-- | fs-tracer/src/main.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/fs-tracer/src/main.rs b/fs-tracer/src/main.rs index 9954900..d11fe90 100644 --- a/fs-tracer/src/main.rs +++ b/fs-tracer/src/main.rs @@ -111,7 +111,7 @@ async fn main() -> Result<(), anyhow::Error> { drop(resolved_files_send); - let batch_timeout = Duration::from_secs(40); + let batch_timeout = Duration::from_secs(20); let mut last_sent_time = Instant::now(); let mut resolved_files_for_request: Vec<FSTracerFile> = vec![]; @@ -149,14 +149,24 @@ struct FSTracerFile { } fn send_request(url: &str, fs_tracer_api_key: &str, files: &Vec<FSTracerFile>) { - //TODO: Retries. We also need to handle when you reopen a file. - let serialized_body = serde_json::to_string(files).unwrap(); - let resp = ureq::post(&url) - .set("API_KEY", &fs_tracer_api_key) - .send_string(&serialized_body) - .expect("Failed to send request"); - if resp.status() != 200 { - panic!("Failed to send request: {:?}", resp); + //TODO: We need to handle when you reopen a file. + let serialized_body = serde_json::to_string(files).expect("failed to serialize failes"); + for _ in 1..4 { + match ureq::post(&url) + .set("API_KEY", &fs_tracer_api_key) + .send_string(&serialized_body) + { + Ok(resp) => { + if resp.status() == 200 { + break; + } + info!("Failed to send request: {:?}", resp); + } + Err(err) => { + info!("Failed to send request: {:?}", err); + } + } } + info!("SENT REQUEST! {:?}", serialized_body); } |