async fn run(&mut self) {
        // perform initial ping to backend to get HTTP certificate
        // if API is trustworthy, then second "expect" should never panic
        let mut crt = self
            .ping_backend()
            .await
            .expect("error pinging backend on initial ping")
            .expect("TLS certificate wasn't provided in initial ping");

        // spawn the HTTP server with the certificate
        // if there is a problem creating it, gracefully shutdown and panic
        let mut server = match http::HttpServerLifecycle::new(Arc::clone(&self.gs), &crt) {
            Ok(srv) => srv,
            Err(e) => {
                log::error!("there was a problem creating the http server: {}", e);
                log::error!("gracefully shutting down then panic due to error...");
                self.shutdown(None).await;
                panic!("error creating HTTP server");
            }
        };

        let mut interval = tokio::time::interval(time::Duration::from_secs(1));
        let mut last_ping = time::Instant::now();
        // set last_shrink to 10 minutes ago so it'll try to shrink the db immediately
        let mut last_shrink = time::Instant::now() - time::Duration::from_secs(600);

        // run until we should begin shutdown sequence
        while !KILL_FLAG.load(atomic::Ordering::SeqCst) {
            interval.tick().await;

            // re-ping server every minute
            if last_ping.elapsed().as_secs() >= 60 {
                last_ping = time::Instant::now();
                // restart actix server if there is a new certificate
                match self.ping_backend().await {
                    Ok(Some(new_crt)) => {
                        crt = new_crt;
                        server.respawn_with_new_cert(&crt).await.unwrap();
                    }
                    Err(e) => log::error!("error pinging backend: {}", e),
                    _ => {} // pass-over
                }
            }

            // attempt to shrink the database every 5 minutes
            if last_shrink.elapsed().as_secs() >= 300 {
                last_shrink = time::Instant::now();
                self.try_shrink_db().await;
            }
        }

        // we are no longer running, we should begin graceful shutdown
        self.shutdown(Some(server)).await;
    }
/// Function that handles all the actions of the main thread.
///
/// This function handles:
/// - Registering the CTRL+C handler
/// - Creating and orchestrating the HTTP Server
/// - Updating the backend server with client settings
/// - Shrinking the cache when it's oversized
/// - Calls function to instigate graceful shutdown when CTRL+C is pressed
Function that handles all the actions of the main thread.
This function handles:
Registering the CTRL+C handler
Creating and orchestrating the HTTP Server
Updating the backend server with client settings
Shrinking the cache when it's oversized
Calls function to instigate graceful shutdown when CTRL+C is pressed
Function that handles all the actions of the main thread . This function handles : Registering the CTRL + C handler Creating and orchestrating the HTTP Server Updating the backend server with client settings Shrinking the cache when it ' s oversized Calls function to instigate graceful shutdown when CTRL + C is pressed
async fn run(&mut self) {
        // perform initial ping to backend to get HTTP certificate
        // if API is trustworthy, then second "expect" should never panic
        let mut crt = self
            .ping_backend()
            .await
            .expect("error pinging backend on initial ping")
            .expect("TLS certificate wasn't provided in initial ping");
        // spawn the HTTP server with the certificate
        // if there is a problem creating it, gracefully shutdown and panic
        let mut server = match http::HttpServerLifecycle::new(Arc::clone(&self.gs), &crt) {
            Ok(srv) => srv,
            Err(e) => {
                log::error!("there was a problem creating the http server: {}", e);
                log::error!("gracefully shutting down then panic due to error...");
                self.shutdown(None).await;
                panic!("error creating HTTP server");
            }
        };
        let mut interval = tokio::time::interval(time::Duration::from_secs(1));
        let mut last_ping = time::Instant::now();
        // set last_shrink to 10 minutes ago so it'll try to shrink the db immediately
        let mut last_shrink = time::Instant::now() - time::Duration::from_secs(600);
        // run until we should begin shutdown sequence
        while !KILL_FLAG.load(atomic::Ordering::SeqCst) {
            interval.tick().await;
            // re-ping server every minute
            if last_ping.elapsed().as_secs() >= 60 {
                last_ping = time::Instant::now();
                // restart actix server if there is a new certificate
                match self.ping_backend().await {
                    Ok(Some(new_crt)) => {
                        crt = new_crt;
                        server.respawn_with_new_cert(&crt).await.unwrap();
                    }
                    Err(e) => log::error!("error pinging backend: {}", e),
                    _ => {} // pass-over
                }
            }
            // attempt to shrink the database every 5 minutes
            if last_shrink.elapsed().as_secs() >= 300 {
                last_shrink = time::Instant::now();
                self.try_shrink_db().await;
            }
        }
        // we are no longer running, we should begin graceful shutdown
        self.shutdown(Some(server)).await;
    }
async fn run ( & mut self ) { // perform initial ping to backend to get HTTP certificate // if API is trustworthy, then second "expect" should never panic let mut crt = self . ping_backend ( ) . await . expect ( " " ) . expect ( " " ) ; // spawn the HTTP server with the certificate // if there is a problem creating it, gracefully shutdown and panic let mut server = match http :: HttpServerLifecycle :: new ( Arc :: clone ( & self . gs ) , & crt ) { Ok ( srv ) => srv , Err ( e ) => { log :: error ! ( " " e ) ; log :: error ! ( " " ) ; self . shutdown ( None ) . await ; panic ! ( " " ) ; } } ; let mut interval = tokio :: time :: interval ( time :: Duration :: from_secs ( 1 ) ) ; let mut last_ping = time :: Instant :: now ( ) ; // set last_shrink to 10 minutes ago so it'll try to shrink the db immediately let mut last_shrink = time :: Instant :: now ( ) - time :: Duration :: from_secs ( 600 ) ; // run until we should begin shutdown sequence while ! KILL_FLAG . load ( atomic :: Ordering :: SeqCst ) { interval . tick ( ) . await ; // re-ping server every minute if last_ping . elapsed ( ) . as_secs ( ) >= 60 { last_ping = time :: Instant :: now ( ) ; // restart actix server if there is a new certificate match self . ping_backend ( ) . await { Ok ( Some ( new_crt ) ) => { crt = new_crt ; server . respawn_with_new_cert ( & crt ) . await . unwrap ( ) ; } Err ( e ) => log :: error ! ( " " e ) , _ => { } // pass-over } } // attempt to shrink the database every 5 minutes if last_shrink . elapsed ( ) . as_secs ( ) >= 300 { last_shrink = time :: Instant :: now ( ) ; self . try_shrink_db ( ) . await ; } } // we are no longer running, we should begin graceful shutdown self . shutdown ( Some ( server ) ) . await ; }
Function that handles all the actions of the main thread.
Function that handles all the actions of the main thread .
&mut self