pub struct HealthPolicy { /* private fields */ }Expand description
Explicit mapping from task states to aggregate health impacts.
The built-in policies are conveniences rather than hidden monitor behavior.
Callers may override any state with HealthPolicy::with_impact.
Implementations§
Source§impl HealthPolicy
impl HealthPolicy
Sourcepub const fn readiness() -> Self
pub const fn readiness() -> Self
A readiness-oriented policy.
Starting and learning tasks are degraded, healthy tasks are nominal, and late or stopped retained tasks are unhealthy.
Examples found in repository?
examples/health_report.rs (line 12)
5fn main() -> Result<(), Box<dyn Error>> {
6 let monitor = Monitor::new();
7 let heartbeat = monitor.register(TaskConfig::new(
8 "api-worker",
9 Timing::fixed(Duration::from_secs(1)),
10 ))?;
11
12 let starting = monitor.summary(HealthPolicy::readiness());
13 println!(
14 "before first beat: verdict={:?}, starting={}",
15 starting.verdict, starting.counts.starting,
16 );
17
18 heartbeat.beat()?;
19
20 let report = monitor.report(HealthPolicy::liveness());
21 println!(
22 "after first beat: verdict={:?}, healthy={}",
23 report.summary.verdict, report.summary.counts.healthy,
24 );
25 for task in report.tasks.iter() {
26 println!("{}: {:?}", task.name, task.health);
27 }
28
29 Ok(())
30}Sourcepub const fn liveness() -> Self
pub const fn liveness() -> Self
A liveness-oriented policy.
Starting, learning, and healthy tasks are nominal. Late tasks are unhealthy. Stopped retained tasks are ignored because they are no longer expected to produce heartbeats.
Examples found in repository?
examples/health_report.rs (line 20)
5fn main() -> Result<(), Box<dyn Error>> {
6 let monitor = Monitor::new();
7 let heartbeat = monitor.register(TaskConfig::new(
8 "api-worker",
9 Timing::fixed(Duration::from_secs(1)),
10 ))?;
11
12 let starting = monitor.summary(HealthPolicy::readiness());
13 println!(
14 "before first beat: verdict={:?}, starting={}",
15 starting.verdict, starting.counts.starting,
16 );
17
18 heartbeat.beat()?;
19
20 let report = monitor.report(HealthPolicy::liveness());
21 println!(
22 "after first beat: verdict={:?}, healthy={}",
23 report.summary.verdict, report.summary.counts.healthy,
24 );
25 for task in report.tasks.iter() {
26 println!("{}: {:?}", task.name, task.health);
27 }
28
29 Ok(())
30}Sourcepub const fn with_impact(self, state: HealthState, impact: HealthImpact) -> Self
pub const fn with_impact(self, state: HealthState, impact: HealthImpact) -> Self
Overrides the impact assigned to one stable task state.
Sourcepub const fn impact(self, state: HealthState) -> HealthImpact
pub const fn impact(self, state: HealthState) -> HealthImpact
Returns the impact assigned to a stable task state.
Trait Implementations§
Source§impl Clone for HealthPolicy
impl Clone for HealthPolicy
impl Copy for HealthPolicy
Source§impl Debug for HealthPolicy
impl Debug for HealthPolicy
Source§impl Default for HealthPolicy
impl Default for HealthPolicy
impl Eq for HealthPolicy
Source§impl Hash for HealthPolicy
impl Hash for HealthPolicy
Source§impl PartialEq for HealthPolicy
impl PartialEq for HealthPolicy
impl StructuralPartialEq for HealthPolicy
Auto Trait Implementations§
impl Freeze for HealthPolicy
impl RefUnwindSafe for HealthPolicy
impl Send for HealthPolicy
impl Sync for HealthPolicy
impl Unpin for HealthPolicy
impl UnsafeUnpin for HealthPolicy
impl UnwindSafe for HealthPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more