hunter/scheduler: add jitter to interval on no new posts
This commit is contained in:
parent
566aecc3dd
commit
e9d3c9aed0
48
Cargo.lock
generated
48
Cargo.lock
generated
|
@ -267,6 +267,7 @@ dependencies = [
|
||||||
"cave",
|
"cave",
|
||||||
"chrono",
|
"chrono",
|
||||||
"log",
|
"log",
|
||||||
|
"rand",
|
||||||
"redis",
|
"redis",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -592,6 +593,17 @@ dependencies = [
|
||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.15"
|
version = "0.3.15"
|
||||||
|
@ -1076,6 +1088,12 @@ version = "0.3.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.47"
|
version = "1.0.47"
|
||||||
|
@ -1094,6 +1112,36 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redis"
|
name = "redis"
|
||||||
version = "0.22.1"
|
version = "0.22.1"
|
||||||
|
|
|
@ -13,3 +13,4 @@ redis = { version = "0.22", features = ["tokio-comp", "connection-manager"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
systemd = "0.10"
|
systemd = "0.10"
|
||||||
cave = { path = "../cave" }
|
cave = { path = "../cave" }
|
||||||
|
rand = "0.8"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::collections::{HashMap, BTreeMap};
|
use std::collections::{HashMap, BTreeMap};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use rand::{thread_rng, Rng};
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
|
|
||||||
const MIN_INTERVAL: Duration = Duration::from_secs(30);
|
const MIN_INTERVAL: Duration = Duration::from_secs(30);
|
||||||
|
@ -56,8 +57,10 @@ impl Scheduler {
|
||||||
let next_interval = match (new_post_ratio, mean_interval, last_interval) {
|
let next_interval = match (new_post_ratio, mean_interval, last_interval) {
|
||||||
(Some(new_post_ratio), Some(mean_interval), _) if new_post_ratio > 0. =>
|
(Some(new_post_ratio), Some(mean_interval), _) if new_post_ratio > 0. =>
|
||||||
mean_interval,
|
mean_interval,
|
||||||
(_, _, Some(last_interval)) =>
|
(_, _, Some(last_interval)) => {
|
||||||
2 * last_interval,
|
let a = thread_rng().gen_range(2. .. 3.);
|
||||||
|
last_interval.mul_f64(a)
|
||||||
|
}
|
||||||
_ =>
|
_ =>
|
||||||
DEFAULT_INTERVAL,
|
DEFAULT_INTERVAL,
|
||||||
}.max(MIN_INTERVAL).min(MAX_INTERVAL);
|
}.max(MIN_INTERVAL).min(MAX_INTERVAL);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user