Skip to content

Commit

Permalink
Add jitter to heartbeat notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed May 10, 2024
1 parent cf4d58f commit 356cf65
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ femme = "2.1.0"
humantime = "2.0.1"
log = "0.4.11"
prometheus-client = "0.22.2"
rand = "0.8.5"
reqwest = "0.12.4"
serde = { version = "1.0.114", features = ["derive"] }
sled = "0.34.2"
Expand Down
5 changes: 4 additions & 1 deletion src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Mutex;
use std::time::SystemTime;

use anyhow::Result;
use rand::Rng;

#[derive(Debug)]
pub struct Schedule {
Expand Down Expand Up @@ -52,7 +53,9 @@ impl Schedule {
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
self.insert_token(token, now)
let mut rng = rand::thread_rng();
let jitter = rng.gen_range(0..60);
self.insert_token(token, now.saturating_add(jitter))
}

pub async fn flush(&self) -> Result<()> {
Expand Down

0 comments on commit 356cf65

Please sign in to comment.