async fn retry_move(&self, pathbuf: PathBuf) {
        use crate::fib_retry;
        use fib_retry::FibonacciBackoff;
        use futures_retry::{ErrorHandler, RetryPolicy};

        // ! can I extract this to it's own module and add error_handler to S3Uploader struct?
        // ! should I?  certainly makes the function shorter.
        impl ErrorHandler<anyhow::Error> for fib_retry::FibonacciBackoff {
            type OutError = anyhow::Error;

            fn handle(
                &mut self,
                current_attempt: usize,
                e: anyhow::Error,
            ) -> RetryPolicy<anyhow::Error> {
                if Some(current_attempt as u64) > self.max_retries {
                    return RetryPolicy::ForwardError(e);
                }

                FAILED_ATTEMPTS.inc();

                match e.downcast_ref::<S3Error>() {
                    Some(S3Error::DeleteFile(_)) | Some(S3Error::PutObject(_)) => match self.next()
                    {
                        Some(duration) => RetryPolicy::WaitRetry(duration),
                        None => RetryPolicy::ForwardError(e),
                    },
                    None => RetryPolicy::ForwardError(e),
                }
            }
        }

        let error_handler = FibonacciBackoff::from_millis(100)
            .max_retries(10)
            .max_delay(Duration::from_secs(6));

        // need to pass &pathbuf here because if we handed ownership over to the function, we wouldn't be able to retry.
        // and I wouldn't be able to delete it either. :)
        let pb = &pathbuf;
        let retval = FutureRetry::new(move || copy_to_s3(pb, self), error_handler.clone()).await;
        match retval {
            Ok(_) => {}
            Err(_) => {
                FAILED_UPLOADS.inc();
                error!(
                    "[{:?}] Exceeded maximum retries ({}) for copy",
                    &pathbuf,
                    error_handler.max_retries.unwrap()
                );
                return;
            }
        }

        // need to pass &pathbuf here because if we handed ownership over to the function, we wouldn't be able to retry.
        let retval = FutureRetry::new(|| delete_local(&pathbuf), error_handler.clone()).await;
        match retval {
            Ok(_) => {}
            Err(_) => {
                FAILED_DELETES.inc();
                error!(
                    "[{:?}] Exceeded maximum retries ({}) for delete",
                    &pathbuf,
                    error_handler.max_retries.unwrap()
                );
                return;
            }
        }

        info!("[{:?}] uploaded successfully.", &pathbuf);
        COMPLETED_UPLOADS.inc();
    }
// attempts to move the specified file to S3
// failures are retried according to the FibonacciBackoff retry strategy.
// in this case, that is determined as 10 retries with a max delay of 6 seconds
attempts to move the specified file to S3
failures are retried according to the FibonacciBackoff retry strategy.
in this case, that is determined as 10 retries with a max delay of 6 seconds
attempts to move the specified file to S3 failures are retried according to the FibonacciBackoff retry strategy . in this case that is determined as 10 retries with a max delay of 6 seconds
async fn retry_move(&self, pathbuf: PathBuf) {
        use crate::fib_retry;
        use fib_retry::FibonacciBackoff;
        use futures_retry::{ErrorHandler, RetryPolicy};
        // ! can I extract this to it's own module and add error_handler to S3Uploader struct?
        // ! should I?  certainly makes the function shorter.
        impl ErrorHandler<anyhow::Error> for fib_retry::FibonacciBackoff {
            type OutError = anyhow::Error;
            fn handle(
                &mut self,
                current_attempt: usize,
                e: anyhow::Error,
            ) -> RetryPolicy<anyhow::Error> {
                if Some(current_attempt as u64) > self.max_retries {
                    return RetryPolicy::ForwardError(e);
                }
                FAILED_ATTEMPTS.inc();
                match e.downcast_ref::<S3Error>() {
                    Some(S3Error::DeleteFile(_)) | Some(S3Error::PutObject(_)) => match self.next()
                    {
                        Some(duration) => RetryPolicy::WaitRetry(duration),
                        None => RetryPolicy::ForwardError(e),
                    },
                    None => RetryPolicy::ForwardError(e),
                }
            }
        }
        let error_handler = FibonacciBackoff::from_millis(100)
            .max_retries(10)
            .max_delay(Duration::from_secs(6));
        // need to pass &pathbuf here because if we handed ownership over to the function, we wouldn't be able to retry.
        // and I wouldn't be able to delete it either. :)
        let pb = &pathbuf;
        let retval = FutureRetry::new(move || copy_to_s3(pb, self), error_handler.clone()).await;
        match retval {
            Ok(_) => {}
            Err(_) => {
                FAILED_UPLOADS.inc();
                error!(
                    "[{:?}] Exceeded maximum retries ({}) for copy",
                    &pathbuf,
                    error_handler.max_retries.unwrap()
                );
                return;
            }
        }
        // need to pass &pathbuf here because if we handed ownership over to the function, we wouldn't be able to retry.
        let retval = FutureRetry::new(|| delete_local(&pathbuf), error_handler.clone()).await;
        match retval {
            Ok(_) => {}
            Err(_) => {
                FAILED_DELETES.inc();
                error!(
                    "[{:?}] Exceeded maximum retries ({}) for delete",
                    &pathbuf,
                    error_handler.max_retries.unwrap()
                );
                return;
            }
        }
        info!("[{:?}] uploaded successfully.", &pathbuf);
        COMPLETED_UPLOADS.inc();
    }
async fn retry_move ( & self , pathbuf : PathBuf ) { use crate :: fib_retry ; use fib_retry :: FibonacciBackoff ; use futures_retry :: { ErrorHandler , RetryPolicy } ; // ! can I extract this to it's own module and add error_handler to S3Uploader struct? // ! should I?  certainly makes the function shorter. impl ErrorHandler < anyhow :: Error > for fib_retry :: FibonacciBackoff { type OutError = anyhow :: Error ; fn handle ( & mut self , current_attempt : usize , e : anyhow :: Error , ) -> RetryPolicy < anyhow :: Error > { if Some ( current_attempt as u64 ) > self . max_retries { return RetryPolicy :: ForwardError ( e ) ; } FAILED_ATTEMPTS . inc ( ) ; match e . downcast_ref :: < S3Error > ( ) { Some ( S3Error :: DeleteFile ( _ ) ) | Some ( S3Error :: PutObject ( _ ) ) => match self . next ( ) { Some ( duration ) => RetryPolicy :: WaitRetry ( duration ) , None => RetryPolicy :: ForwardError ( e ) , } , None => RetryPolicy :: ForwardError ( e ) , } } } let error_handler = FibonacciBackoff :: from_millis ( 100 ) . max_retries ( 10 ) . max_delay ( Duration :: from_secs ( 6 ) ) ; // need to pass &pathbuf here because if we handed ownership over to the function, we wouldn't be able to retry. // and I wouldn't be able to delete it either. :) let pb = & pathbuf ; let retval = FutureRetry :: new ( move | | copy_to_s3 ( pb , self ) , error_handler . clone ( ) ) . await ; match retval { Ok ( _ ) => { } Err ( _ ) => { FAILED_UPLOADS . inc ( ) ; error ! ( " " pathbuf error_handler max_retries unwrap ( ) ) ; return ; } } // need to pass &pathbuf here because if we handed ownership over to the function, we wouldn't be able to retry. let retval = FutureRetry :: new ( | | delete_local ( & pathbuf ) , error_handler . clone ( ) ) . await ; match retval { Ok ( _ ) => { } Err ( _ ) => { FAILED_DELETES . inc ( ) ; error ! ( " " pathbuf error_handler max_retries unwrap ( ) ) ; return ; } } info ! ( " " pathbuf ) ; COMPLETED_UPLOADS . inc ( ) ; }
attempts to move the specified file to S3
failures are retried according to the FibonacciBackoff retry strategy.
attempts to move the specified file to S3 failures are retried according to the FibonacciBackoff retry strategy .
&self
pathbuf
PathBuf
&self
pathbuf
PathBuf