Git Product home page Git Product logo

rust-futures-backoff's Introduction

futures-backoff

Asynchronous retry strategies based on futures.

Build Status crates dependency status

Documentation

Installation

Add this to your Cargo.toml:

[dependencies]
futures-backoff = "0.1"

Examples

extern crate futures;
extern crate futures_backoff;

use futures::{Future, future};
use futures_backoff::retry;

fn main() {
    let future = retry(|| {
        // do some real-world stuff here...
        future::ok::<u32, ::std::io::Error>(42)
    });

    let result = future.wait();

    assert_eq!(result, Ok(42));
}

rust-futures-backoff's People

Contributors

srijs avatar compressed avatar bbigras avatar df5602 avatar

Stargazers

 avatar nuxeh avatar Yongjin Jung avatar GAURAV avatar Daniel Neuhäuser avatar Juri Hahn avatar Andrejs Agejevs avatar Doug Tangren avatar asonix avatar

Watchers

James Cloos avatar  avatar asonix avatar  avatar

Forkers

bcmcmill

rust-futures-backoff's Issues

Condition#should_retry invoked more than expected

Thanks for this library. I've taken a look at a number of retry libraries for rust futures and this by far has the most straightforward and well thought out interface.

I'm working this into a client library and am trying to implement a Condition type that debug logs how many time an operation was retried. Here's a sketch

/// Predicate trait that determines if an impl
/// type is retryable
trait Retry {
    /// Return true if type is retryable
    fn retryable(&self) -> bool;
}

struct Counter(u16);

impl<R> Condition<R> for Counter
where
    R: Retry,
{
    fn should_retry(
        &mut self,
        error: &R,
    ) -> bool {
        log::debug!("retrying operation {}", self.0);
        self.0 += 1;
        error.retryable()
    }
}
Strategy::exponential(duration)
  .with_max_retries(5)
  .with_jitter(true)
  .retry_if(
    operation,
    Counter(0)
)

when I try a forced failing operation, I see some suprising output.

retrying operation 0
retrying operation 0
retrying operation 1
retrying operation 2
retrying operation 3
retrying operation 4
retrying operation 5

I'm wondering if this is expected.

What I expected was that the condition would be invoked once per future failure.

Error when using lapin futures with this crate.

Hi,
When I attempt to use https://github.com/sozu-proxy/lapin-futures-tls/tree/master/native-tls with this crate, I get the following error.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SpawnError { is_shutdown: true }', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

Not sure why this is happening because I am sure that I am in a tokio runtime.

My Code:

let strategy = Strategy::fibonacci(Duration::from_secs(2))
            .with_max_retries(10);
        let gr = group.clone();
        let (amqp, _) = strategy.retry(|| {
            amqp_uri.connect_cancellable(|err| {
                eprintln!("Error encountered while attempting heartbeat. {}", err);
            })
        }).wait().unwrap();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.