Skip to content

Commit

Permalink
Await healthy endpoint (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Apr 10, 2024
1 parent cdbdd9b commit ef1c524
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/extensions/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use anyhow::anyhow;
use async_trait::async_trait;
use futures::FutureExt as Boxed;
use jsonrpsee::core::{client::Subscription, Error, JsonValue};
use opentelemetry::trace::FutureExt;
use rand::{seq::SliceRandom, thread_rng};
Expand Down Expand Up @@ -204,13 +205,12 @@ impl Client {
if let Some(exclude) = exclude {
endpoints.retain(|e| e.url() != exclude.url());
}
// wait for at least one endpoint to connect
futures::future::select_all(endpoints.iter().map(|x| x.connected().boxed())).await;
// Sort by health score
endpoints.sort_by_key(|endpoint| std::cmp::Reverse(endpoint.health().score()));
// Pick the first one
let selected_endpoint = endpoints[0].clone();
// Ensure it's connected
selected_endpoint.connected().await;
selected_endpoint
endpoints[0].clone()
};

let mut selected_endpoint = healthiest_endpoint(None).await;
Expand Down

0 comments on commit ef1c524

Please sign in to comment.