Skip to content

Commit

Permalink
cohost2autost: use exponential backoff for attachment redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Dec 31, 2024
1 parent cfab1e8 commit ecb074c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::{
fs::{copy, create_dir_all, read_dir, File},
io::{Read, Write},
path::Path,
thread::sleep,
time::Duration,
};

use jane_eyre::eyre::{self, bail, OptionExt};
Expand Down Expand Up @@ -237,7 +239,8 @@ fn cache_cohost_attachment(
.redirect(Policy::none())
.build()?;

let mut retries = 2;
let mut retries = 4;
let mut wait = Duration::from_secs(4);
let mut redirect;
let url = loop {
let result = client.head(url).send();
Expand All @@ -247,6 +250,9 @@ fn cache_cohost_attachment(
if retries == 0 {
bail!("failed to get attachment redirect (after retries): {url}: {error:?}");
} else {
warn!(?wait, url, ?error, "retrying failed request");
sleep(wait);
wait *= 2;
retries -= 1;
continue;
}
Expand Down Expand Up @@ -276,6 +282,9 @@ fn cache_cohost_attachment(
redirect.status()
);
} else {
warn!(?wait, url, status = ?redirect.status(), "retrying failed request");
sleep(wait);
wait *= 2;
retries -= 1;
continue;
}
Expand Down

0 comments on commit ecb074c

Please sign in to comment.