Skip to content

Commit

Permalink
Only cache ip updates if all providers succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Oct 18, 2024
1 parent b48d78d commit 838b030
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["command-line-utilities", "network-programming"]
readme = "README.md"

[dependencies]
anyhow = "1.0.89"
anyhow = "1.0.90"
async-trait = "0.1.83"
clap = { version = "4.5.20", features = ["derive"] }
hickory-resolver = "0.24.1"
Expand All @@ -27,7 +27,7 @@ reqwest = { version = "0.12.8", features = [
"rustls-tls",
], default-features = false }
serde = { version = "1.0.210", features = ["serde_derive"] }
serde_json = "1.0.128"
serde_json = "1.0.129"
smallvec = { version = "1.13.2", features = ["serde"] }
stun = "0.6.0"
tokio = { version = "1.40.0", features = [
Expand Down
16 changes: 10 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,18 @@ impl Client {
continue;
}
info!("IP address update detected, updating providers...");
let mut failed = false;
for provider in &self.config.providers {
provider.update(&update, &self.request).await?;
if let Err(error) = provider.update(&update, &self.request).await {
error!("Failed to update provider: {error}");
failed = true;
}
}
if !failed {
info!("Providers updated successfully wih IP(s): {update}");
let mut cache = self.cache.write().await;
*cache = update;
}
info!("Providers updated successfully wih IP(s): {update}");
// TODO: Only write on successful update
debug!("Saving IP address update to cache...");
let mut cache = self.cache.write().await;
*cache = update;
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/providers/cloudflare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ impl Provider for Cloudflare {
if updated.success {
debug!("Record updated: {:#?}", updated);
} else {
error!("Failed to update record: {:#?}", updated);
error!("Failed to update domain ({}) record: {:#?}", domain.name, updated);
return Err(anyhow!("Failed to update domain ({}) record", domain.name));
}
} else {
debug!(
Expand All @@ -148,7 +149,8 @@ impl Provider for Cloudflare {
if created.success {
debug!("Record created: {:#?}", created);
} else {
error!("Failed to create record: {:#?}", created);
error!("Failed to create domain ({}) record: {:#?}", domain.name, created);
return Err(anyhow!("Failed to create domain ({}) record", domain.name));
}
};
}
Expand Down

0 comments on commit 838b030

Please sign in to comment.