failsafe-rs

所属分类:硬件设计
开发工具:Rust
文件大小:0KB
下载次数:0
上传日期:2022-12-12 20:14:41
上 传 者sh-1993
说明:  生锈的断路器实施,
(A circuit breaker implementation for rust,)

文件列表:
.appveyor.yml (956, 2022-08-22)
.circleci/ (0, 2022-08-22)
.circleci/cache-key (346, 2022-08-22)
.circleci/cargo-lint (467, 2022-08-22)
.circleci/config.yml (1765, 2022-08-22)
CHANGELOG.md (1983, 2022-08-22)
Cargo.lock (23104, 2022-08-22)
Cargo.toml (914, 2022-08-22)
benches/ (0, 2022-08-22)
benches/circuit_breaker.rs (1668, 2022-08-22)
benches/futures.rs (1510, 2022-08-22)
benches/state_machine.rs (1484, 2022-08-22)
benches/windowed_adder.rs (582, 2022-08-22)
src/ (0, 2022-08-22)
src/backoff.rs (7681, 2022-08-22)
src/circuit_breaker.rs (3969, 2022-08-22)
src/clock.rs (1340, 2022-08-22)
src/config.rs (1779, 2022-08-22)
src/ema.rs (4119, 2022-08-22)
src/error.rs (747, 2022-08-22)
src/failure_policy.rs (14784, 2022-08-22)
src/failure_predicate.rs (847, 2022-08-22)
src/futures/ (0, 2022-08-22)
src/futures/mod.rs (7068, 2022-08-22)
src/instrument.rs (728, 2022-08-22)
src/lib.rs (2903, 2022-08-22)
src/state_machine.rs (12911, 2022-08-22)
src/windowed_adder.rs (6778, 2022-08-22)

# Failsafe [![Сrate](https://img.shields.io/crates/v/failsafe.svg)](https://crates.io/crates/failsafe) [![Вocumentation](https://docs.rs/failsafe/badge.svg)](https://docs.rs/failsafe) [![CircleCI](https://circleci.com/gh/dmexe/failsafe-rs.svg?style=svg)](https://circleci.com/gh/dmexe/failsafe-rs) [![Appveyor](https://ci.appveyor.com/api/projects/status/c0qrj9dbskneunjg/branch/master?svg=true)](https://ci.appveyor.com/project/dmexe/failsafe-rs/branch/master) A circuit breaker implementation which used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties. * [https://martinfowler.com/bliki/CircuitBreaker.html](https://martinfowler.com/bliki/CircuitBreaker.html) * [Read documentation](https://docs.rs/failsafe/1.2.0/failsafe) # Features * Working with both `Fn() -> Result` and `Future` (optional via default `futures-support` feature). * Backoff strategies: `constant`, `exponential`, `equal_jittered`, `full_jittered` * Failure detection policies: `consecutive_failures`, `success_rate_over_time_window` * Minimum rust version: 1.49 # Usage Add this to your Cargo.toml: ```toml failsafe = "1.2.0" ``` # Example Using default backoff strategy and failure accrual policy. ```rust use failsafe::{Config, CircuitBreaker, Error}; // A function that sometimes failed. fn dangerous_call() -> Result<(), ()> { if thread_rng().gen_range(0, 2) == 0 { return Err(()) } Ok(()) } // Create a circuit breaker which configured by reasonable default backoff and // failure accrual policy. let circuit_breaker = Config::new().build(); // Call the function in a loop, after some iterations the circuit breaker will // be in a open state and reject next calls. for n in 0..100 { match circuit_breaker.call(|| dangerous_call()) { Err(Error::Inner(_)) => { eprintln!("{}: fail", n); }, Err(Error::Rejected) => { eprintln!("{}: rejected", n); break; }, _ => {} } } ``` Or configure custom backoff and policy: ```rust use std::time::Duration; use failsafe::{backoff, failure_policy, CircuitBreaker}; // Create an exponential growth backoff which starts from 10s and ends with 60s. let backoff = backoff::exponential(Duration::from_secs(10), Duration::from_secs(60)); // Create a policy which failed when three consecutive failures were made. let policy = failure_policy::consecutive_failures(3, backoff); // Creates a circuit breaker with given policy. let circuit_breaker = Config::new() .failure_policy(policy) .build(); ```

近期下载者

相关文件


收藏者