Skip to content

Commit

Permalink
chore: remove error on run()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolay-komarevskiy committed Jul 17, 2024
1 parent 22fd241 commit e7b6395
Showing 1 changed file with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
time::{Duration, Instant},
};

use anyhow::anyhow;
use arc_swap::ArcSwap;
use candid::Principal;
use reqwest::Client;
Expand Down Expand Up @@ -143,9 +142,7 @@ impl<S> DynamicRouteProviderBuilder<S> {
token: CancellationToken::new(),
};

if let Err(err) = route_provider.run().await {
error!("{DYNAMIC_ROUTE_PROVIDER}: started in unhealthy state: {err:?}");
}
route_provider.run().await;

route_provider
}
Expand Down Expand Up @@ -175,8 +172,8 @@ where
/// - Listens to the fetched nodes messages from the NodesFetchActor.
/// - Starts/stops health check tasks (HealthCheckActors) based on the newly added/removed nodes.
/// - These spawned health check tasks periodically update the snapshot with the latest node health info.
pub async fn run(&self) -> anyhow::Result<()> {
info!("{DYNAMIC_ROUTE_PROVIDER}: start run() ");
pub async fn run(&self) {
info!("{DYNAMIC_ROUTE_PROVIDER}: started ...");
// Communication channel between NodesFetchActor and HealthManagerActor.
let (fetch_sender, fetch_receiver) = watch::channel(None);

Expand All @@ -196,31 +193,24 @@ where
.spawn(async move { health_manager_actor.run().await });

// Dispatch all seed nodes for initial health checks
let start = Instant::now();
if let Err(err) = fetch_sender.send(Some(FetchedNodes {
nodes: self.seeds.clone(),
})) {
error!("{DYNAMIC_ROUTE_PROVIDER}: failed to send results to HealthManager: {err:?}");
}

// Try await for healthy seeds.
let found_healthy_seeds =
match timeout(TIMEOUT_AWAIT_HEALTHY_SEED, init_receiver.recv()).await {
Ok(_) => {
info!(
"{DYNAMIC_ROUTE_PROVIDER}: found healthy seeds within {:?}",
start.elapsed()
);
true
}
Err(_) => {
warn!(
"{DYNAMIC_ROUTE_PROVIDER}: no healthy seeds found within {:?}",
start.elapsed()
);
false
}
};
let start = Instant::now();
match timeout(TIMEOUT_AWAIT_HEALTHY_SEED, init_receiver.recv()).await {
Ok(_) => info!(
"{DYNAMIC_ROUTE_PROVIDER}: found healthy seeds within {:?}",
start.elapsed()
),
Err(_) => warn!(
"{DYNAMIC_ROUTE_PROVIDER}: no healthy seeds found within {:?}",
start.elapsed()
),
};
// We can close the channel now.
init_receiver.close();

Expand All @@ -236,10 +226,6 @@ where
info!(
"{DYNAMIC_ROUTE_PROVIDER}: NodesFetchActor and HealthManagerActor started successfully"
);

(found_healthy_seeds).then_some(()).ok_or(anyhow!(
"No healthy seeds found within {TIMEOUT_AWAIT_HEALTHY_SEED:?}, they may become healthy later ..."
))
}
}

Expand Down Expand Up @@ -696,3 +682,7 @@ mod tests {
);
}
}

// - none of the seeds [] are healthy
// - none of the API node [] is healthy
// - return a vector of errors: HealthCheckErrors, FetchErrors, etc.

0 comments on commit e7b6395

Please sign in to comment.