#retry #backoff #fault-tolerance #resilience #rust

resilient-rs

A Rust utility library for fault tolerance, including retry strategies, backoff mechanisms, and failure handling

8 unstable releases (3 breaking)

new 0.4.2 Mar 6, 2025
0.4.1 Mar 5, 2025
0.3.0 Mar 1, 2025
0.2.1 Mar 1, 2025
0.1.1 Feb 28, 2025

#194 in Concurrency

Download history

410 downloads per month

MIT license

39KB
623 lines

Resilient-rs

A Rust utility library for fault tolerance, including retry strategies, backoff mechanisms, failure handling and much more.

Join Community Badge GitHub contributors Crates.io Downloads Docs.rs

πŸ’– Loved the work? Subscribe to my YouTube channel or consider giving this repository a ⭐ to show your support!

Feature Overview

Feature Details Status
Retry Basic retry functionality βœ… Stable
With Backoff (exponential) βœ… Stable
With Fallback βœ… Stable
Circuit Breaker Prevents cascading failures πŸ› οΈ Planned
Logging Comprehensive debugging support βœ… Stable
More Examples Additional usage examples πŸ› οΈ Planned

Notes:

  • Supported Contexts: All features are available for both synchronous and asynchronous operations.

πŸ“¦ How to Use resilient-rs

Here’s a quick example of how to use the resilient-rs crate in your Rust project.

1️⃣ Add resilient-rs to Your Cargo.toml

Add the following line to your Cargo.toml file:

[dependencies]
resilient-rs = "0.4.2" # Replace with the latest version

OR

cargo add resilient-rs

Synchronous

use std::time::Duration;
use resilient_rs::config::RetryConfig;
use resilient_rs::synchronous::retry;

fn main() {
  let retry_config = RetryConfig::default();
  let result: Result<i32, &str> = retry(|| {
    Err("Temporary failure")
  }, &retry_config);
  assert!(result.is_err());
}

Asynchronous

use tokio::time::Duration;
use reqwest::Client;
use resilient_rs::asynchronous::retry;
use resilient_rs::config::RetryConfig;

async fn fetch_url() -> Result<String, reqwest::Error> {
  let client = Client::new();
  let response = client.get("https://example.com")
          .send()
          .await?;

  if response.status().is_success() {
    response.text().await
  } else {
    Err(reqwest::Error::new(reqwest::StatusCode::from_u16(response.status().as_u16()).unwrap(), "Request failed"))
  }
}

#[tokio::main]
async fn main() {
  let retry_config = RetryConfig::default();

  let result = retry(fetch_url, &retry_config).await;
  match result {
    Ok(output) => println!("Operation succeeded: {}", output),
    Err(err) => println!("Operation failed: {}", err),
  }
}

πŸš€ Contributing Guidelines

We welcome your contributions! Here's how to get started:

πŸ› Issues & 🌟 Features

  • Find an issue or planned feature you'd like to work on.
  • Comment on the issue (or create one for planned features) and tag me (@semicolon-10) for assignment.
    πŸ’‘ Tip: Ensure it's not already assigned!
  • Once assigned, start working. πŸŽ‰

πŸ”§ Submitting Work

  1. 🍴 Fork the repo and create a new branch.
  2. πŸ› οΈ Make changes and test thoroughly.
  3. βœ… Ensure git actions pass before tagging me for review.
  4. πŸ“€ Submit a PR with a clear description and link the issue.

🀝 Code of Conduct

  • Be respectful and collaborative. πŸ€—
  • Follow coding standards and guidelines. βœ…

Dependencies

~5–13MB
~183K SLoC