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",
|
"chrono",
|
||||||
"feed-rs",
|
"feed-rs",
|
||||||
"matrix-sdk",
|
"matrix-sdk",
|
||||||
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
|
@ -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"
|
||||||
|
@ -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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user