main: Implement exponential backoff in the feed fetcher loop
Backoff with an exponentially increasing delay when feeds can't be fetched or parsed, with a maximum of 6h (after which retry every 6h)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1295,7 +1295,7 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
|
||||
|
||||
[[package]]
|
||||
name = "matrix-feedbot"
|
||||
version = "0.1.2"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "matrix-feedbot"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
authors = ["mirsal <mirsal@mirsal.fr>"]
|
||||
|
10
src/main.rs
10
src/main.rs
@ -59,6 +59,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
let handles: Vec<JoinHandle<_>> = config.feeds.clone().into_iter().map(|feed_config| {
|
||||
let state_db = Arc::clone(&state_db);
|
||||
let bcast_tx = bcast_tx.clone();
|
||||
let mut backoff: u64 = feed_config.delay;
|
||||
|
||||
tokio::spawn(async move {
|
||||
|
||||
@ -80,10 +81,15 @@ async fn main() -> anyhow::Result<()> {
|
||||
};
|
||||
|
||||
let feed = if feed.is_none() {
|
||||
debug!("Sleeping for {} seconds before refreshing this feed", feed_config.delay);
|
||||
sleep(Duration::from_secs(feed_config.delay)).await;
|
||||
backoff = max(backoff * 2, 6 * 3600);
|
||||
error!("Backing off for {} seconds", backoff);
|
||||
sleep(Duration::from_secs(backoff)).await;
|
||||
continue;
|
||||
} else {
|
||||
if backoff != feed_config.delay {
|
||||
debug!("Resetting exponential backoff timer");
|
||||
backoff = feed_config.delay;
|
||||
}
|
||||
feed.unwrap()
|
||||
};
|
||||
|
||||
|
@ -98,7 +98,7 @@ pub async fn login_and_sync<T: Clone>(
|
||||
client
|
||||
.matrix_auth()
|
||||
.login_username(username, password)
|
||||
.initial_device_display_name("bender v0.1.3")
|
||||
.initial_device_display_name("bender v0.1.4")
|
||||
.await?;
|
||||
|
||||
info!("logged in as {username}");
|
||||
|
Reference in New Issue
Block a user