-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use exponential backoff with jitter where applicable * dedup and finish
- Loading branch information
Showing
27 changed files
with
278 additions
and
187 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use std::fmt; | ||
|
||
pub struct TransparentDebug<T>(pub T); | ||
|
||
impl<T> fmt::Debug for TransparentDebug<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{} {{ ... }}", std::any::type_name::<T>()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "kitsune-retry-policies" | ||
edition.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
futures-retry-policies = { version = "0.3.1", features = [ | ||
"retry-policies", | ||
"tokio", | ||
"tracing", | ||
] } | ||
retry-policies = "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use futures_retry_policies::{retry_policies::RetryPolicies, tracing::Traced}; | ||
use retry_policies::{policies::ExponentialBackoff, Jitter}; | ||
use std::{ | ||
fmt::{self, Debug}, | ||
ops::ControlFlow, | ||
time::{Duration, SystemTime}, | ||
}; | ||
|
||
pub use futures_retry_policies::{tokio::RetryFutureExt, RetryPolicy}; | ||
|
||
pub struct NeverRetry<T>(T); | ||
|
||
impl<T> Debug for NeverRetry<T> | ||
where | ||
T: Debug, | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} | ||
|
||
impl<T> futures_retry_policies::ShouldRetry for NeverRetry<T> { | ||
fn should_retry(&self, _attempts: u32) -> bool { | ||
false | ||
} | ||
} | ||
|
||
impl<Res, T> futures_retry_policies::RetryPolicy<Res> for NeverRetry<T> | ||
where | ||
T: futures_retry_policies::RetryPolicy<NeverRetry<Res>>, | ||
{ | ||
fn should_retry(&mut self, result: Res) -> ControlFlow<Res, Duration> { | ||
match self.0.should_retry(NeverRetry(result)) { | ||
ControlFlow::Break(NeverRetry(val)) => ControlFlow::Break(val), | ||
ControlFlow::Continue(dur) => ControlFlow::Continue(dur), | ||
} | ||
} | ||
} | ||
|
||
pub fn futures_backoff_policy<Res>() -> impl futures_retry_policies::RetryPolicy<Res> | ||
where | ||
Res: Debug, | ||
{ | ||
Traced(NeverRetry(RetryPolicies::new(backoff_policy()))) | ||
} | ||
|
||
pub fn backoff_policy() -> impl retry_policies::RetryPolicy { | ||
ExponentialBackoff::builder() | ||
.jitter(Jitter::Bounded) | ||
.build_with_total_retry_duration(Duration::from_secs(24 * 3600)) // Kill the retrying after 24 hours | ||
.for_task_started_at(SystemTime::now().into()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ mod tests { | |
.unwrap(); | ||
let resource = match response { | ||
Either::E1(Json(resource)) => resource, | ||
Either::E2(status) => panic!("Unexpected status code: {}", status), | ||
Either::E2(status) => panic!("Unexpected status code: {status}"), | ||
}; | ||
|
||
assert_eq!(resource.subject, "acct:[email protected]"); | ||
|
@@ -191,7 +191,7 @@ mod tests { | |
.unwrap(); | ||
let resource = match response { | ||
Either::E1(Json(resource)) => resource, | ||
Either::E2(status) => panic!("Unexpected status code: {}", status), | ||
Either::E2(status) => panic!("Unexpected status code: {status}"), | ||
}; | ||
|
||
assert_eq!(resource.subject, "acct:[email protected]"); | ||
|
@@ -203,7 +203,7 @@ mod tests { | |
let response = get(db_pool, url_service, Query(query)).await.unwrap(); | ||
let resource = match response { | ||
Either::E1(Json(resource)) => resource, | ||
Either::E2(status) => panic!("Unexpected status code: {}", status), | ||
Either::E2(status) => panic!("Unexpected status code: {status}"), | ||
}; | ||
|
||
assert_eq!(resource.subject, "acct:[email protected]"); | ||
|
Oops, something went wrong.