From 6dddbfb1e9ba1232a07f296974e6611e371f98e8 Mon Sep 17 00:00:00 2001 From: mirsal Date: Tue, 26 Nov 2024 21:34:21 +0000 Subject: [PATCH] main: Add a randomized delay before fetching feeds --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7d5b491..a17290f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1301,6 +1301,7 @@ dependencies = [ "chrono", "feed-rs", "matrix-sdk", + "rand", "reqwest", "serde", "serde_yaml", diff --git a/Cargo.toml b/Cargo.toml index 6e19ecf..6e00af4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ license = "GPL-3.0-or-later" authors = ["mirsal "] [dependencies] +rand = "0.8" serde = "1.0" anyhow = "1.0" chrono = "0.4" diff --git a/src/main.rs b/src/main.rs index f3e42aa..0108182 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,11 @@ async fn main() -> anyhow::Result<()> { tokio::spawn(async move { loop { + let delay = rand::random::() % (feed_config.delay / 5); + + debug!("Adding randomized delay: {}", delay); + sleep(Duration::from_secs(delay)).await; + let feed: Option<_> = match fetch_and_parse_feed(&feed_config.url).await { Ok(f) => Some(f), Err(e) => {