mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 13:16:56 +00:00
chore: Tidy up backoff helper code
This commit is contained in:
1 parent
bc1826de66
commit
79c9f7da30
4 files changed
+24
-42
No files matched your search
@@ -6,10 +6,7 @@ use assign::assign;
|
||||
use async_trait::async_trait;
|
||||
use conduwuit::{
|
||||
Error, Result, Server, SyncRwLock, debug,
|
||||
utils::{
|
||||
math::Expected, millis_since_unix_epoch,
|
||||
time::exponential_backoff::min_exp_backoff_duration,
|
||||
},
|
||||
utils::{math::Expected, millis_since_unix_epoch, time::exponential_backoff::next_interval},
|
||||
};
|
||||
pub(crate) use execute::FederationPathBuilderInput;
|
||||
use http::StatusCode;
|
||||
@@ -94,12 +91,12 @@ impl Service {
|
||||
return;
|
||||
}
|
||||
|
||||
let min = self.services.server.config.sender_timeout;
|
||||
let max = self.services.server.config.sender_retry_backoff_limit;
|
||||
let min = Duration::from_secs(self.services.server.config.sender_timeout);
|
||||
let max = Duration::from_secs(self.services.server.config.sender_retry_backoff_limit);
|
||||
|
||||
*retries = retries.saturating_add(1);
|
||||
*next_retry = unix_now.saturating_add(
|
||||
u64::try_from(min_exp_backoff_duration(min, max, *retries).as_millis())
|
||||
u64::try_from(next_interval(min, max, *retries).as_millis())
|
||||
.expect("backoff milliseconds should not exceed u64::MAX"),
|
||||
);
|
||||
debug!(
|
||||
|
||||
@@ -10,14 +10,15 @@ use std::{
|
||||
|
||||
use base64::{Engine as _, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||
use conduwuit::{
|
||||
debug_info, debug_warn, info, utils::time::exponential_backoff::min_exp_backoff_duration,
|
||||
debug_info, debug_warn, info,
|
||||
utils::{should_continue_backoff, time::exponential_backoff::next_interval},
|
||||
};
|
||||
use conduwuit_core::{
|
||||
Error, Event, Result, at, debug, err, error,
|
||||
matrix::pdu::sticky,
|
||||
result::LogErr,
|
||||
utils::{
|
||||
ReadyExt, calculate_hash, continue_exponential_backoff_secs,
|
||||
ReadyExt, calculate_hash,
|
||||
future::TryExtExt,
|
||||
stream::{BroadbandExt, IterStream, WidebandExt},
|
||||
},
|
||||
@@ -409,13 +410,12 @@ impl Service {
|
||||
.entry(dest.clone())
|
||||
.and_modify(|e| match e {
|
||||
| TransactionStatus::Failed(tries, time) => {
|
||||
// Fail if a request has failed recently (exponential backoff)
|
||||
let min = self.server.config.sender_timeout;
|
||||
let max = self.server.config.sender_retry_backoff_limit;
|
||||
if continue_exponential_backoff_secs(min, max, time.elapsed(), *tries)
|
||||
let min = Duration::from_secs(self.server.config.sender_timeout);
|
||||
let max = Duration::from_secs(self.server.config.sender_retry_backoff_limit);
|
||||
if should_continue_backoff(min, max, time.elapsed(), *tries)
|
||||
&& !matches!(dest, Destination::Appservice(_))
|
||||
{
|
||||
let retry_after = min_exp_backoff_duration(min, max, *tries);
|
||||
let retry_after = next_interval(min, max, *tries);
|
||||
debug_warn!("Not retrying destination for another {retry_after:?}");
|
||||
allow = false;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user