Skip to content

Commit

Permalink
fixe() removing tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
ndefokou committed Dec 12, 2024
1 parent ae52335 commit 6c1b4be
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use shared::{
repository::entity::Connection,
retry::{retry_async, RetryOptions},
state::{AppState, AppStateRepository},
CircuitBreaker::CircuitBreaker,

Check warning on line 26 in crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/handler/stateful.rs

View workflow job for this annotation

GitHub Actions / Build and test

unused import: `CircuitBreaker::CircuitBreaker`

Check warning on line 26 in crates/web-plugins/didcomm-messaging/protocols/mediator-coordination/src/handler/stateful.rs

View workflow job for this annotation

GitHub Actions / Build and test

unused import: `CircuitBreaker::CircuitBreaker`
};
use std::{sync::Arc, time::Duration};
use uuid::Uuid;
Expand Down Expand Up @@ -110,7 +111,7 @@ pub(crate) async fn process_mediate_request(
RetryOptions::new()
.retries(5)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(1)),
.max_delay(Duration::from_secs(2)),
)
.await
.map_err(|err| {
Expand Down Expand Up @@ -268,7 +269,7 @@ pub(crate) async fn process_plain_keylist_update_message(
RetryOptions::new()
.retries(5)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(1)),
.max_delay(Duration::from_secs(2)),
)
.await
.map_err(|err| {
Expand Down Expand Up @@ -404,7 +405,7 @@ pub(crate) async fn process_plain_keylist_query_message(
RetryOptions::new()
.retries(5)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(1)),
.max_delay(Duration::from_secs(2)),
)
.await
.map_err(|err| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub(crate) enum PickupError {

#[error("Malformed request. {0}")]
MalformedRequest(String),

#[error("Service unavailable")]
CircuitOpen,

Check warning on line 19 in crates/web-plugins/didcomm-messaging/protocols/pickup/src/error.rs

View workflow job for this annotation

GitHub Actions / Build and test

variant `CircuitOpen` is never constructed
}

impl IntoResponse for PickupError {
Expand All @@ -22,6 +25,7 @@ impl IntoResponse for PickupError {
PickupError::MissingSenderDID | PickupError::MalformedRequest(_) => {
StatusCode::BAD_REQUEST
}
PickupError::CircuitOpen => StatusCode::SERVICE_UNAVAILABLE,
PickupError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
PickupError::MissingClientConnection => StatusCode::UNAUTHORIZED,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub(crate) async fn handle_delivery_request(
RetryOptions::new()
.retries(5)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(1)),
.max_delay(Duration::from_secs(2)),
)
.await?;

Expand Down Expand Up @@ -211,7 +211,7 @@ pub(crate) async fn handle_message_acknowledgement(
RetryOptions::new()
.retries(5)
.exponential_backoff(Duration::from_millis(100))
.max_delay(Duration::from_secs(1)),
.max_delay(Duration::from_secs(2)),
)
.await
.map_err(|_| {
Expand Down
27 changes: 0 additions & 27 deletions crates/web-plugins/didcomm-messaging/shared/src/CircuitBreaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,3 @@ impl CircuitBreaker {
Ok(Some(result))
}
}

// pub fn request(dice: u32) -> Result<u32, String> {
// if dice > 6 {
// Err("400: Bad request.".to_string())
// } else {
// Ok(dice)
// }
// }

// // Example usage
// fn main() {
// let breaker = CircuitBreaker::new(3, Duration::from_secs(5));

// for i in 1..=10 {
// let result = breaker.call(|| request(i));

// match result {
// Ok(Some(Ok(value))) => println!("Request succeeded with value: {}", value),
// Ok(Some(Err(err))) => println!("Request failed: {}", err),
// Ok(None) => println!("Circuit breaker is open."),
// Err(err) => println!("Error: {}", err),
// }

// // Simulate a delay between requests
// thread::sleep(Duration::from_millis(500));
// }
// }

0 comments on commit 6c1b4be

Please sign in to comment.