-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): the restarting policy can be overridden via configuration…
… for each actor. `RestartParams` have been added for `RestartPolicy::always(..)` and `RestartPolicy::on_failure(..)`. The linear backoff has been replaced with an exponential approach, with a configurable limit for restarts. BREAKING CHANGE: The default RestartPolicy is set to `RestartPolicy::never()`.
- Loading branch information
Showing
24 changed files
with
601 additions
and
141 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{num::NonZeroU64, time::Duration}; | ||
|
||
use serde::{Deserialize, Deserializer}; | ||
|
||
use crate::restarting::restart_policy::{RestartParams, RestartPolicy}; | ||
|
||
#[derive(Debug, Default)] | ||
pub(crate) struct RestartingConfig { | ||
pub(crate) overriding_policy: Option<RestartPolicy>, | ||
} | ||
|
||
impl<'de> Deserialize<'de> for RestartingConfig { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
Option::<RestartPolicyConfig>::deserialize(deserializer).map(|p| RestartingConfig { | ||
overriding_policy: p.map(Into::into), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct RestartParamsConfig { | ||
#[serde(with = "humantime_serde")] | ||
min_backoff: Duration, | ||
#[serde(with = "humantime_serde")] | ||
max_backoff: Duration, | ||
#[serde(with = "humantime_serde", default)] | ||
auto_reset: Option<Duration>, | ||
max_retries: Option<NonZeroU64>, | ||
#[serde(default)] | ||
factor: Option<f32>, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(tag = "when")] | ||
enum RestartPolicyConfig { | ||
Always(RestartParamsConfig), | ||
OnFailure(RestartParamsConfig), | ||
Never, | ||
} | ||
|
||
impl From<RestartPolicyConfig> for RestartPolicy { | ||
fn from(p: RestartPolicyConfig) -> Self { | ||
match p { | ||
RestartPolicyConfig::Always(p) => RestartPolicy::always(p.into()), | ||
RestartPolicyConfig::OnFailure(p) => RestartPolicy::on_failure(p.into()), | ||
RestartPolicyConfig::Never => RestartPolicy::never(), | ||
} | ||
} | ||
} | ||
|
||
impl From<RestartParamsConfig> for RestartParams { | ||
fn from(p: RestartParamsConfig) -> Self { | ||
let restart_params = RestartParams::new(p.min_backoff, p.max_backoff); | ||
let restart_params = p | ||
.factor | ||
.map(|f| restart_params.factor(f)) | ||
.unwrap_or(restart_params); | ||
let restart_params = p | ||
.max_retries | ||
.map(|max_retries| restart_params.max_retries(max_retries)) | ||
.unwrap_or(restart_params); | ||
p.auto_reset | ||
.map(|auto_reset| restart_params.auto_reset(auto_reset)) | ||
.unwrap_or(restart_params) | ||
} | ||
} |
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,5 @@ | ||
mod config; | ||
mod restart_policy; | ||
|
||
pub(crate) use self::config::RestartingConfig; | ||
pub use restart_policy::{RestartParams, RestartPolicy}; |
Oops, something went wrong.