Struct replicante_util_upkeep::Upkeep
source · [−]pub struct Upkeep { /* private fields */ }
Expand description
Block the calling thread until shutdown is requested.
Shutdown is requested when:
- The process receives SIGINT.
- A registered thread panics.
- A required thread exists (optional threads are allowed to exit gracefully).
Shutdown Flow
- Request all registered threads to shutdown.
- Execute all on_shutdown callbacks. 3 Wait for all registered threads to exit.
Threads and handlers are iterated on in registration order.
Signal Handling
When a process is sent SIGINT the shutdown flow begins. The process is allowed to take as long as it wants to shutdown.
If a second SIGINT is received while the process is shutting down it will instead exit immediately.
Example
let mut up = Upkeep::new();
up.on_shutdown(|| println!("Bye :wave:"));
up.keepalive();
Implementations
sourceimpl Upkeep
impl Upkeep
pub fn new() -> Upkeep
sourcepub fn keepalive(&mut self) -> bool
pub fn keepalive(&mut self) -> bool
Block the calling thread waiting for the process to shutdown.
Returns
This method returns true
if the process shuts down cleanly.
sourcepub fn on_shutdown<F>(&mut self, callback: F)where
F: Fn() + 'static,
pub fn on_shutdown<F>(&mut self, callback: F)where
F: Fn() + 'static,
Register a callback to be executed when a shutdown request is received.
sourcepub fn register_signal(&mut self) -> Result<(), Error>
pub fn register_signal(&mut self) -> Result<(), Error>
Register signal handers for SIGINT and SIGTERM.
sourcepub fn register_thread<T: Send + 'static>(&mut self, thread: Thread<T>)
pub fn register_thread<T: Send + 'static>(&mut self, thread: Thread<T>)
sourcepub fn register_thread_optional<T: Send + 'static>(&mut self, thread: Thread<T>)
pub fn register_thread_optional<T: Send + 'static>(&mut self, thread: Thread<T>)
Similar to Upkeep::register_thread
but clean exists do not shutdown the process.
sourcepub fn set_logger(&mut self, logger: Logger)
pub fn set_logger(&mut self, logger: Logger)
Set the logger to be used by the Upkeep
instance.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Upkeep
impl !Send for Upkeep
impl !Sync for Upkeep
impl Unpin for Upkeep
impl !UnwindSafe for Upkeep
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more