aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index f2fa2ec..ddf54d8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ use std::{
io::{BufReader, BufWriter, Read, Write},
path::{Path, PathBuf},
sync::mpsc::channel,
+ thread,
time::Duration,
};
@@ -23,6 +24,7 @@ mod discord;
const DPS_REPORT_API: &str = "https://dps.report/uploadContent";
const WATCH_DELAY_SECONDS: u64 = 2;
+const RETRY_DELAY: Duration = Duration::from_secs(5);
#[derive(Clap, Debug, Clone, PartialEq, Eq, Hash)]
#[clap(version = "0.1")]
@@ -161,7 +163,24 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> {
return Ok(());
}
- let permalink = upload_log(filename)?;
+ let mut try_counter = 0;
+ let permalink = loop {
+ let result = upload_log(filename);
+ if let Ok(link) = result {
+ break link;
+ }
+ warn!(
+ "Upload try {} failed, retrying {} more times. Reason: {}",
+ try_counter + 1,
+ config.retries - try_counter,
+ result.as_ref().unwrap_err(),
+ );
+ if try_counter == config.retries {
+ return Err(result.unwrap_err());
+ }
+ try_counter += 1;
+ thread::sleep(RETRY_DELAY);
+ };
info!("Uploaded log, available at {}", permalink);
if let Some(d) = &config.discord {