fn exec_with_retries<F, T>(&self, f: F) -> QueryResult<T>
    where
        F: Fn() -> QueryResult<T>,
    {
        // If retrying is not enabled, we simply execute the task once.
        if !self.retrying_enabled.get() {
            return f();
        }

        for attempt in 1..=RETRIES_AMOUNT {
            match f() {
                Ok(result) => {
                    return Ok(result);
                }
                Err(error) => {
                    // In case of error encountered, we're gonna retry the connection, since
                    // most likely the error is caused by some issue with the database server.
                    log::warn!(
                        "Error while interacting with database ({}), retry attempt #{}",
                        error,
                        attempt
                    );

                    std::thread::sleep(scale_retry_period(attempt));
                    if let Ok(conn) = Conn::establish(self.database_url.as_ref()) {
                        log::info!(
                            "Connection with the database reestablished after {} retries",
                            attempt
                        );
                        *self.connection.borrow_mut() = conn;
                    }
                }
            }
        }

        // At this point we are sure that either database is down
        // or the query is incorrect; we cannot work without a database.
        panic!("Cannot connect to the database after several retries, it is probably down");
    }
/// Performs the query (represented as a closure) with a prior knowledge
/// that the database can sometimes stop responding for short periods of time.
///
/// In case of the database unavailability, the same request is repeated with
/// increasing time intervals.
Performs the query (represented as a closure) with a prior knowledge
that the database can sometimes stop responding for short periods of time.

In case of the database unavailability, the same request is repeated with
increasing time intervals.
Performs the query ( represented as a closure ) with a prior knowledge that the database can sometimes stop responding for short periods of time . In case of the database unavailability the same request is repeated with increasing time intervals .
fn exec_with_retries<F, T>(&self, f: F) -> QueryResult<T>
    where
        F: Fn() -> QueryResult<T>,
    {
        // If retrying is not enabled, we simply execute the task once.
        if !self.retrying_enabled.get() {
            return f();
        }
        for attempt in 1..=RETRIES_AMOUNT {
            match f() {
                Ok(result) => {
                    return Ok(result);
                }
                Err(error) => {
                    // In case of error encountered, we're gonna retry the connection, since
                    // most likely the error is caused by some issue with the database server.
                    log::warn!(
                        "Error while interacting with database ({}), retry attempt #{}",
                        error,
                        attempt
                    );
                    std::thread::sleep(scale_retry_period(attempt));
                    if let Ok(conn) = Conn::establish(self.database_url.as_ref()) {
                        log::info!(
                            "Connection with the database reestablished after {} retries",
                            attempt
                        );
                        *self.connection.borrow_mut() = conn;
                    }
                }
            }
        }
        // At this point we are sure that either database is down
        // or the query is incorrect; we cannot work without a database.
        panic!("Cannot connect to the database after several retries, it is probably down");
    }
fn exec_with_retries < F , T > ( & self , f : F ) -> QueryResult < T > where F : Fn ( ) -> QueryResult < T > , { // If retrying is not enabled, we simply execute the task once. if ! self . retrying_enabled . get ( ) { return f ( ) ; } for attempt in 1 ..= RETRIES_AMOUNT { match f ( ) { Ok ( result ) => { return Ok ( result ) ; } Err ( error ) => { // In case of error encountered, we're gonna retry the connection, since // most likely the error is caused by some issue with the database server. log :: warn ! ( " " error attempt ) ; std :: thread :: sleep ( scale_retry_period ( attempt ) ) ; if let Ok ( conn ) = Conn :: establish ( self . database_url . as_ref ( ) ) { log :: info ! ( " " attempt ) ; * self . connection . borrow_mut ( ) = conn ; } } } } // At this point we are sure that either database is down // or the query is incorrect; we cannot work without a database. panic ! ( " " ) ; }
Performs the query (represented as a closure) with a prior knowledge
that the database can sometimes stop responding for short periods of time.
Performs the query ( represented as a closure ) with a prior knowledge that the database can sometimes stop responding for short periods of time .
&self
f
F