mirror of https://github.com/LemmyNet/lemmy.git
ignore first error
parent
e4abdefe09
commit
2c56bf8ad5
|
@ -48,8 +48,14 @@ impl Default for SuccessResponse {
|
||||||
const DAY: Duration = Duration::from_secs(3600);
|
const DAY: Duration = Duration::from_secs(3600);
|
||||||
|
|
||||||
/// Calculate how long to sleep until next federation send based on how many
|
/// Calculate how long to sleep until next federation send based on how many
|
||||||
/// retries have already happened. Uses exponential backoff with maximum of one day.
|
/// retries have already happened. Uses exponential backoff with maximum of one day. The first
|
||||||
|
/// error is ignored.
|
||||||
pub fn federate_retry_sleep_duration(retry_count: i32) -> Duration {
|
pub fn federate_retry_sleep_duration(retry_count: i32) -> Duration {
|
||||||
|
debug_assert!(retry_count != 0);
|
||||||
|
if retry_count == 1 {
|
||||||
|
return Duration::from_secs(0);
|
||||||
|
}
|
||||||
|
let retry_count = retry_count - 1;
|
||||||
let pow = 1.25_f64.powf(retry_count.into());
|
let pow = 1.25_f64.powf(retry_count.into());
|
||||||
let pow = Duration::try_from_secs_f64(pow).unwrap_or(DAY);
|
let pow = Duration::try_from_secs_f64(pow).unwrap_or(DAY);
|
||||||
min(DAY, pow)
|
min(DAY, pow)
|
||||||
|
@ -61,10 +67,15 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_federate_retry_sleep_duration() {
|
fn test_federate_retry_sleep_duration() {
|
||||||
let s = |s,m: u32| Duration::new(s, m * 1000);
|
assert_eq!(Duration::from_secs(0), federate_retry_sleep_duration(1));
|
||||||
assert_eq!(s(1, 0), federate_retry_sleep_duration(0));
|
assert_eq!(
|
||||||
assert_eq!(s(1, 250000), federate_retry_sleep_duration(1));
|
Duration::new(1, 250000000),
|
||||||
assert_eq!(s(1, 562500), federate_retry_sleep_duration(2));
|
federate_retry_sleep_duration(2)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Duration::new(2, 441406250),
|
||||||
|
federate_retry_sleep_duration(5)
|
||||||
|
);
|
||||||
assert_eq!(DAY, federate_retry_sleep_duration(100));
|
assert_eq!(DAY, federate_retry_sleep_duration(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue