#[non_exhaustive]pub enum ShutdownEvent {
Draining {
active_connections: usize,
drain_timeout: Option<Duration>,
},
DrainTimedOut {
remaining_connections: usize,
},
}Expand description
An event emitted during graceful shutdown.
Register a handler with ServerBuilder::on_shutdown_event to receive these.
When no handler is registered, the server logs via tracing::warn by default.
§Example
use icap_rs::{IcapResult, Server, ShutdownEvent};
#[tokio::main]
async fn main() -> IcapResult<()> {
let server = Server::builder()
.bind("127.0.0.1:1344")
.on_shutdown_event(|event| match event {
ShutdownEvent::Draining { active_connections, drain_timeout } => {
eprintln!("shutting down: {active_connections} connections in flight");
if let Some(d) = drain_timeout {
eprintln!("force-close in {d:.1?}");
}
}
ShutdownEvent::DrainTimedOut { remaining_connections } => {
eprintln!("drain timed out, cancelling {remaining_connections} connections");
}
_ => {}
})
.build()
.await?;
server.run_until(async { tokio::signal::ctrl_c().await.ok(); }).await
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Draining
Shutdown signal received; drain phase starting.
New connections are refused with 503 Service Unavailable.
active_connections are still processing requests.
If drain_timeout is set, remaining connections will be force-cancelled after it expires.
Fields
DrainTimedOut
Drain deadline expired; remaining connections are being cancelled.
Trait Implementations§
Source§impl Clone for ShutdownEvent
impl Clone for ShutdownEvent
Source§fn clone(&self) -> ShutdownEvent
fn clone(&self) -> ShutdownEvent
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ShutdownEvent
Auto Trait Implementations§
impl Freeze for ShutdownEvent
impl RefUnwindSafe for ShutdownEvent
impl Send for ShutdownEvent
impl Sync for ShutdownEvent
impl Unpin for ShutdownEvent
impl UnsafeUnpin for ShutdownEvent
impl UnwindSafe for ShutdownEvent
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