async fn shutdown(&self, server: Option<http::HttpServerLifecycle>) {
        // ping the backend server for stop, so that we'll stop receiving requests sometime soon
        log::info!("sending stop signal to API");
        if let Err(e) = self.gs.backend.stop().await {
            log::error!("error fulfilling stop API request: {}", e);
        }

        // wait until there are no more requests coming in
        let start = time::Instant::now();
        let mut requests = self.get_num_requests();
        let grace = self.gs.config.max_grace_period;
        loop {
            // immediately stop graceful shutdown if configured
            if grace < 0 {
                break;
            }
            tokio::time::sleep(time::Duration::from_secs(5)).await;

            // break if we've had no requests in the interval
            let x = self.get_num_requests();
            if x == requests {
                break;
            }
            requests = x;

            let elapsed = start.elapsed().as_secs() as i32;
            log::info!("waited for shutdown for {} seconds", elapsed);
            // break if we've waited for more seconds than the max grace period
            if grace != 0 && elapsed >= grace {
                break;
            }
        }

        if let Some(srv) = server {
            log::info!("shutting down actix web server");
            srv.shutdown(true).await;
        }
    }
/// Function for gracefully shutting down the actix server and application as a whole. This
/// function will wait until there are no more requests coming in OR that the time has exceeded
/// the configured maximum grace period.
///
/// This does not, however, gracefully shut down the actix server (wait for all keep-alives to
/// drop) as that would take much time on top of the grace period.
Function for gracefully shutting down the actix server and application as a whole. This
function will wait until there are no more requests coming in OR that the time has exceeded
the configured maximum grace period.

This does not, however, gracefully shut down the actix server (wait for all keep-alives to
drop) as that would take much time on top of the grace period.
Function for gracefully shutting down the actix server and application as a whole . This function will wait until there are no more requests coming in OR that the time has exceeded the configured maximum grace period . This does not however gracefully shut down the actix server ( wait for all keep - alives to drop ) as that would take much time on top of the grace period .
async fn shutdown(&self, server: Option<http::HttpServerLifecycle>) {
        // ping the backend server for stop, so that we'll stop receiving requests sometime soon
        log::info!("sending stop signal to API");
        if let Err(e) = self.gs.backend.stop().await {
            log::error!("error fulfilling stop API request: {}", e);
        }
        // wait until there are no more requests coming in
        let start = time::Instant::now();
        let mut requests = self.get_num_requests();
        let grace = self.gs.config.max_grace_period;
        loop {
            // immediately stop graceful shutdown if configured
            if grace < 0 {
                break;
            }
            tokio::time::sleep(time::Duration::from_secs(5)).await;
            // break if we've had no requests in the interval
            let x = self.get_num_requests();
            if x == requests {
                break;
            }
            requests = x;
            let elapsed = start.elapsed().as_secs() as i32;
            log::info!("waited for shutdown for {} seconds", elapsed);
            // break if we've waited for more seconds than the max grace period
            if grace != 0 && elapsed >= grace {
                break;
            }
        }
        if let Some(srv) = server {
            log::info!("shutting down actix web server");
            srv.shutdown(true).await;
        }
    }
async fn shutdown ( & self , server : Option < http :: HttpServerLifecycle > ) { // ping the backend server for stop, so that we'll stop receiving requests sometime soon log :: info ! ( " " ) ; if let Err ( e ) = self . gs . backend . stop ( ) . await { log :: error ! ( " " e ) ; } // wait until there are no more requests coming in let start = time :: Instant :: now ( ) ; let mut requests = self . get_num_requests ( ) ; let grace = self . gs . config . max_grace_period ; loop { // immediately stop graceful shutdown if configured if grace < 0 { break ; } tokio :: time :: sleep ( time :: Duration :: from_secs ( 5 ) ) . await ; // break if we've had no requests in the interval let x = self . get_num_requests ( ) ; if x == requests { break ; } requests = x ; let elapsed = start . elapsed ( ) . as_secs ( ) as i32 ; log :: info ! ( " " elapsed ) ; // break if we've waited for more seconds than the max grace period if grace != 0 && elapsed >= grace { break ; } } if let Some ( srv ) = server { log :: info ! ( " " ) ; srv . shutdown ( true ) . await ; } }
Function for gracefully shutting down the actix server and application as a whole.
Function for gracefully shutting down the actix server and application as a whole .
&self
server
Option<http::HttpServerLifecycle>