main: Add a randomized delay before fetching feeds
This commit is contained in:
parent
24d824f759
commit
6dddbfb1e9
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1301,6 +1301,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"feed-rs",
|
||||
"matrix-sdk",
|
||||
"rand",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
|
@ -6,6 +6,7 @@ license = "GPL-3.0-or-later"
|
||||
authors = ["mirsal <mirsal@mirsal.fr>"]
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
serde = "1.0"
|
||||
anyhow = "1.0"
|
||||
chrono = "0.4"
|
||||
|
@ -63,6 +63,11 @@ async fn main() -> anyhow::Result<()> {
|
||||
tokio::spawn(async move {
|
||||
|
||||
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 {
|
||||
Ok(f) => Some(f),
|
||||
Err(e) => {
|
||||
|
Loading…
Reference in New Issue
Block a user