Skip to main content

ShutdownProbe

Struct ShutdownProbe 

Source
pub struct ShutdownProbe { /* private fields */ }
Expand description

Polls a set of ShutdownComponents until they all drain or the deadline elapses.

§Example

use dev_async::shutdown::{ShutdownComponent, ShutdownProbe};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;

let drained = Arc::new(AtomicBool::new(true));
let comp = {
    let drained = drained.clone();
    ShutdownComponent::new("worker", move || {
        let d = drained.clone();
        async move { d.load(Ordering::Relaxed) }
    })
};

let probe = ShutdownProbe::new("system")
    .deadline(Duration::from_millis(200))
    .poll_interval(Duration::from_millis(10))
    .with_component(comp);

let checks = probe.run().await;
assert!(!checks.is_empty());

Implementations§

Source§

impl ShutdownProbe

Source

pub fn new(name: impl Into<String>) -> Self

Begin building a probe with a stable name.

Source

pub fn deadline(self, d: Duration) -> Self

Maximum time to wait for the system to drain.

Source

pub fn poll_interval(self, d: Duration) -> Self

How often to re-evaluate each component’s drain predicate.

Source

pub fn with_component(self, component: ShutdownComponent) -> Self

Add a component to the probe.

Source

pub async fn run(self) -> Vec<CheckResult>

Run the probe and return one CheckResult per component plus an aggregate.

Per-component verdicts:

  • Drained before deadline -> Pass with elapsed_ms evidence.
  • Did not drain in time -> Fail (Error) with not_drained tag.

The aggregate verdict is Fail if any component failed, otherwise Pass. It is the last entry in the returned vector and tagged aggregate.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.