diff --git a/src/attachments.rs b/src/attachments.rs index dbe3acd..e579441 100644 --- a/src/attachments.rs +++ b/src/attachments.rs @@ -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}; @@ -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(); @@ -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; } @@ -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; }