diff options
| author | Baitinq <[email protected]> | 2024-06-11 23:38:30 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2024-06-11 23:38:30 +0200 |
| commit | 2a3a7e023afaf19242b1a61be955def65fc3f584 (patch) | |
| tree | 5ee51524b93074af7fd815a164c3493747cec161 | |
| parent | fs-tracer: fix threads not exiting (diff) | |
| download | fs-tracer-2a3a7e023afaf19242b1a61be955def65fc3f584.tar.gz fs-tracer-2a3a7e023afaf19242b1a61be955def65fc3f584.tar.bz2 fs-tracer-2a3a7e023afaf19242b1a61be955def65fc3f584.zip | |
fs-tracer: handle sending unbatched requests when exiting
| -rw-r--r-- | fs-tracer/src/main.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/fs-tracer/src/main.rs b/fs-tracer/src/main.rs index d1adc19..2a79db1 100644 --- a/fs-tracer/src/main.rs +++ b/fs-tracer/src/main.rs @@ -119,18 +119,28 @@ async fn main() -> Result<(), anyhow::Error> { } let request_body = format!("[{}]", batched_req.join(",")); - //TODO: Retries - let resp = ureq::post(&url) - .set("API_KEY", &fs_tracer_api_key) - .send_string(&request_body) - .expect("Failed to send request"); - if resp.status() != 200 { - panic!("Failed to send request: {:?}", resp); - } + send_request(&url, &fs_tracer_api_key, &request_body); info!("SENT REQUEST! {:?}, {:?}", batched_req.len(), request_body); batched_req.clear(); } + info!("All threads stopped, exiting now..."); + if !batched_req.is_empty() { + let request_body = format!("[{}]", batched_req.join(",")); + send_request(&url, &fs_tracer_api_key, &request_body); + } + Ok(()) } + +fn send_request(url: &str, fs_tracer_api_key: &str, request_body: &str) { + //TODO: Retries + let resp = ureq::post(&url) + .set("API_KEY", &fs_tracer_api_key) + .send_string(&request_body) + .expect("Failed to send request"); + if resp.status() != 200 { + panic!("Failed to send request: {:?}", resp); + } +} |