pub struct ShutdownCoordinator { /* private fields */ }Expand description
Coordinates graceful shutdown across the system.
§Shutdown phases
- Stop accepting — signal is broadcast, new requests get 503.
- Drain in-flight — wait for the in-flight counter to reach zero.
- Cage all gorillas — stop autonomous agents.
- Flush logs — give tracing subscribers time to flush.
- Close DB — release database handles.
Hooks registered via register_hook
fire in registration order after the drain phase.
Implementations§
Source§impl ShutdownCoordinator
impl ShutdownCoordinator
Sourcepub fn new(drain_timeout: Duration) -> Arc<Self>
pub fn new(drain_timeout: Duration) -> Arc<Self>
Create a new shutdown coordinator with the given drain timeout.
Sourcepub fn with_default_timeout() -> Arc<Self>
pub fn with_default_timeout() -> Arc<Self>
Create a coordinator with the default 30-second drain timeout.
Sourcepub fn subscribe(&self) -> Receiver<bool>
pub fn subscribe(&self) -> Receiver<bool>
Subscribe to the shutdown signal.
The returned receiver yields true once shutdown is initiated.
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Returns true if shutdown has been initiated.
Sourcepub fn track_request(&self) -> bool
pub fn track_request(&self) -> bool
Increment the in-flight request counter.
Returns false if shutdown is in progress (caller should reject
the request with 503).
Sourcepub fn finish_request(&self)
pub fn finish_request(&self)
Decrement the in-flight request counter.
Sourcepub fn in_flight_count(&self) -> usize
pub fn in_flight_count(&self) -> usize
Current number of in-flight requests.
Sourcepub async fn register_hook<F, Fut>(&self, hook: F)
pub async fn register_hook<F, Fut>(&self, hook: F)
Register a hook that will be called during shutdown.
Hooks fire in registration order after the drain phase completes or times out.
Sourcepub async fn initiate_shutdown(&self)
pub async fn initiate_shutdown(&self)
Initiate graceful shutdown.
This method is idempotent — calling it multiple times has no additional effect.
- Broadcasts the shutdown signal (new requests will be rejected).
- Waits for in-flight requests to drain (up to
drain_timeout). - Runs all registered hooks in order.
Auto Trait Implementations§
impl !Freeze for ShutdownCoordinator
impl !RefUnwindSafe for ShutdownCoordinator
impl Send for ShutdownCoordinator
impl Sync for ShutdownCoordinator
impl Unpin for ShutdownCoordinator
impl UnsafeUnpin for ShutdownCoordinator
impl !UnwindSafe for ShutdownCoordinator
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more