main: Add a randomized delay before fetching feeds

This commit is contained in:
mirsal 2024-11-26 21:34:21 +00:00
parent 24d824f759
commit 6dddbfb1e9
Signed by: mirsal
GPG Key ID: F78F9FE84AE5B610
3 changed files with 7 additions and 0 deletions

1
Cargo.lock generated
View File

@ -1301,6 +1301,7 @@ dependencies = [
"chrono", "chrono",
"feed-rs", "feed-rs",
"matrix-sdk", "matrix-sdk",
"rand",
"reqwest", "reqwest",
"serde", "serde",
"serde_yaml", "serde_yaml",

View File

@ -6,6 +6,7 @@ license = "GPL-3.0-or-later"
authors = ["mirsal <mirsal@mirsal.fr>"] authors = ["mirsal <mirsal@mirsal.fr>"]
[dependencies] [dependencies]
rand = "0.8"
serde = "1.0" serde = "1.0"
anyhow = "1.0" anyhow = "1.0"
chrono = "0.4" chrono = "0.4"

View File

@ -63,6 +63,11 @@ async fn main() -> anyhow::Result<()> {
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
let delay = rand::random::<u64>() % (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 { let feed: Option<_> = match fetch_and_parse_feed(&feed_config.url).await {
Ok(f) => Some(f), Ok(f) => Some(f),
Err(e) => { Err(e) => {