aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-07-17 16:07:39 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-07-17 16:13:38 +0200
commit420869dab5dc73e86a7915f5cc29da4a9291a586 (patch)
treea3215be4d2d61c540d02666bc457240991aa2e83
parentf511152cb33743026503297a18a74f118dec4bc6 (diff)
downloadezau-420869dab5dc73e86a7915f5cc29da4a9291a586.tar.gz
ezau-420869dab5dc73e86a7915f5cc29da4a9291a586.tar.bz2
ezau-420869dab5dc73e86a7915f5cc29da4a9291a586.zip
retry uploading
As it turns out, uploading is often the reason why the process crashes/exits. This is bad because it means that 1) we lose links to logs (as they are not being uploaded), leading to incomplete reporting and 2) we rely on an external watchdog to keep the service alive (and I'd rather just not have ezau crashing, especially on Windows where we usually don't supervise it with systemd). Therefore, a configuration setting has been added that lets ezau retry the upload process. This is not 100% good and failsafe, because 1) it always waits a hardcoded amount of seconds (instead of e.g. using a proper backoff timer) 2) it blocks the rest of the process, so no logs will be compressed while it is retrying a single log 3) after those retries, the process will still exit But it is a good first approximation, and the aforementioned issues can be fixed "relatively easily" (e.g. by moving the whole per-log logic into a separate thread(pool) and handling failures even better).
-rw-r--r--README.md6
-rw-r--r--ezau-sample.toml6
-rw-r--r--src/config.rs3
-rw-r--r--src/main.rs21
4 files changed, 35 insertions, 1 deletions
diff --git a/README.md b/README.md
index 08dff28..c257000 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,12 @@ upload = false
# (optional)
upload_unknown = false
+# How often uploading a log should be retried when it failed.
+# Note that this does not include the first try, so a value of 0 means "try it
+# once".
+# (optional)
+retries = 0
+
# Discord messaging section.
# If this section is missing, ezau will not do Discord notifications for log uploads.
# Mandatory keys in this section are only mandatory if the section is present, as the whole Discord functionality is optional.
diff --git a/ezau-sample.toml b/ezau-sample.toml
index a18d6ad..77d96a8 100644
--- a/ezau-sample.toml
+++ b/ezau-sample.toml
@@ -8,6 +8,12 @@ upload = false
# (optional)
upload_unknown = false
+# How often uploading a log should be retried when it failed.
+# Note that this does not include the first try, so a value of 0 means "try it
+# once".
+# (optional)
+retries = 0
+
# Discord messaging section.
# If this section is missing, ezau will not do Discord notifications for log uploads.
# Mandatory keys in this section are only mandatory if the section is present, as the whole Discord functionality is optional.
diff --git a/src/config.rs b/src/config.rs
index e4203de..6b9a89d 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -11,6 +11,9 @@ pub struct Config {
/// Flag indicating whether logs with an unknown boss should be uploaded.
#[serde(default)]
pub upload_unknown: bool,
+ /// How often the upload to dps.report should be retried.
+ #[serde(default)]
+ pub retries: u32,
/// Option Discord information for bot postings.
pub discord: Option<Discord>,
}
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 {