Skip to content

Commit

Permalink
Merge #123
Browse files Browse the repository at this point in the history
123: Force the delay between retried http requests to be 10s r=TristanDebrunner a=TristanDebrunner

Fixes #114

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
bors[bot] and TristanDebrunner authored Dec 1, 2022
2 parents ad4a1c2 + 81638db commit 0a13a51
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{
use tokio::{
sync::{mpsc, watch},
task,
time::{timeout_at, Duration, Instant},
time::{sleep_until, timeout_at, Duration, Instant},
};
use tokio_serial::SerialPortBuilder;
use uwh_common::{
Expand Down Expand Up @@ -194,9 +194,17 @@ impl RefBoxApp {
let request = client.request(Method::GET, url).build().unwrap();
let client_ = client.clone();
let msg_tx_ = self.msg_tx.clone();

let mut delay_until = None;

task::spawn(async move {
let mut msg = None;
for _ in 0..MAX_RETRIES {
if let Some(time) = delay_until.take() {
sleep_until(time).await;
}

let start = Instant::now();
msg = match client_.execute(request.try_clone().unwrap()).await {
Ok(resp) => {
if resp.status() != StatusCode::OK {
Expand All @@ -220,6 +228,7 @@ impl RefBoxApp {
Err(e) => {
error!("Request for {} failed: {e}", short_name);
info!("Maybe retrying");
delay_until = Some(start + REQUEST_TIMEOUT);
continue;
}
};
Expand Down

0 comments on commit 0a13a51

Please sign in to comment.