-
-
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.
- Loading branch information
Showing
13 changed files
with
107 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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