pub struct Vigil { /* private fields */ }
Expand description
Represents a single vigil over the code. Should be notified every tick_interval
, if enough
intervals pass without a notification the callback will be fired (on a separate thread).
Implementations§
source§impl Vigil
impl Vigil
sourcepub fn create(
interval_ms: usize,
missed_test_cb: Option<Box<dyn Fn() + Send + 'static>>,
at_risk_cb: Option<Box<dyn Fn() + Send + 'static>>,
stall_detected_cb: Option<Box<dyn Fn() + Send + 'static>>
) -> (Self, JoinHandle<()>)
pub fn create(
interval_ms: usize,
missed_test_cb: Option<Box<dyn Fn() + Send + 'static>>,
at_risk_cb: Option<Box<dyn Fn() + Send + 'static>>,
stall_detected_cb: Option<Box<dyn Fn() + Send + 'static>>
) -> (Self, JoinHandle<()>)
Create a new vigil object. The three callbacks are all optional. Note that no callbacks will be fired until the first notification has occurred (this allows the vigil to be created ahead of the worker thread without causing spurious logs/callbacks).
sourcepub fn notify(&self)
pub fn notify(&self)
Indicate to the vigil that the code is still active and alive. This should be done in the
same thread that is actively processing work (e.g. not in a dedicated notifier thread)
otherwise deadlocks will not be caught. If the processing thread knows it will be
unavailable to notify for an extended period of time, it should use set_interval
rather
than faking up notifications.
sourcepub fn set_interval(&self, interval_ms: usize)
pub fn set_interval(&self, interval_ms: usize)
Change the interval between expected notifications. Useful if a worker thread is expecting
to block on a long operation (e.g. a blocking HTTP request, or a CPU intensive
calculation). This interval will be changed until set_interval
is called again (so code
should shorten the interval once the long-blocking work is completed).