Skip to content

Commit

Permalink
handle error in request batcher
Browse files Browse the repository at this point in the history
  • Loading branch information
dekkku committed Sep 12, 2024
1 parent 891eb02 commit 9ed11a9
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions projects/dekkku/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,31 @@ impl RequestBatcher {

tokio::spawn(async move {
let result = fetch_with_retry(&client, &url).await;

if let Ok(response) = result {
if let Ok(body) = response.bytes().await {
// let's say in queue, we've got around 10k requests and only one is executing right now.
// and if it fails then we won't reach here to remove the all requests from queue
// handle that scenario.
let senders = { on_going_req.remove(&url) };
let senders = on_going_req.remove(&url);

match result {
Ok(response) => match response.bytes().await {
Ok(body) => {
if let Some((_, senders)) = senders {
for sender in senders {
let _ = sender.send(Ok(body.clone()));
}
}
}
Err(e) => {
if let Some((_, senders)) = senders {
for sender in senders {
let err = anyhow::anyhow!(e.to_string());
let _ = sender.send(Err(err));
}
}
}
},
Err(e) => {
if let Some((_, senders)) = senders {
for sender in senders {
let _ = sender.send(Ok(body.clone()));
let err = anyhow::anyhow!(e.to_string());
let _ = sender.send(Err(err));
}
}
}
Expand Down

0 comments on commit 9ed11a9

Please sign in to comment.