Skip to content

Commit 24a4e38

Browse files
committed
Retry getting sites
1 parent f0afb6f commit 24a4e38

3 files changed

Lines changed: 43 additions & 39 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "historyprovider"
33
description = "historyprovider-rs"
44
license = "MIT"
55
repository = "https://github.com/silicon-heaven/historyprovider-rs"
6-
version = "2.7.9"
6+
version = "2.7.10"
77
edition = "2024"
88

99
[[bin]]

src/sites.rs

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -390,50 +390,54 @@ pub(crate) async fn sites_task(
390390

391391
let mut online_status_task = None;
392392

393-
loop {
393+
'main_loop: loop {
394394
futures::select! {
395395
client_event = client_evt_rx.select_next_some() => match client_event {
396396
shvclient::ClientEvent::Connected(shv_api_version) => {
397397
log::info!("Getting sites info");
398398

399-
let sites: Result<shvproto::Map, _> = RpcCall::new("sites", "getSites")
400-
.exec(&client_cmd_tx)
401-
.await;
402-
403-
let (sites_info, sub_hps) = match sites {
404-
Ok(sites) => {
405-
if sites
406-
.get("_meta")
407-
.map(RpcValue::as_map)
408-
.and_then(|map| map.get("HP3"))
409-
.map(RpcValue::as_map)
410-
.and_then(|map| map.get("type"))
411-
.map(RpcValue::as_str)
412-
.is_none_or(|type_str| type_str != "HP3")
413-
{
414-
eprintln!("This site's _meta does NOT include an HP3 node. Refusing to continue. Add an HP3 node to the site's _meta, otherwise this HP instance will not be visible to parent HPs.");
415-
std::process::abort();
416-
}
417-
let sub_hps = collect_sub_hps(&[], &sites);
418-
let mut sites_info = collect_sites(&[], &sites);
419-
for (path, site_info) in &mut sites_info {
420-
if let Some((prefix, _)) = find_longest_path_prefix(&sub_hps, path) {
421-
site_info.sub_hp = prefix.into();
422-
} else {
423-
log::error!("Cannot find sub HP for site {path}");
424-
site_info.sub_hp = path.clone();
399+
let (sites_info, sub_hps) = 'sites_get_loop: loop {
400+
let sites: Result<shvproto::Map, _> = RpcCall::new("sites", "getSites")
401+
.exec(&client_cmd_tx)
402+
.await;
403+
404+
match sites {
405+
Ok(sites) => {
406+
if sites
407+
.get("_meta")
408+
.map(RpcValue::as_map)
409+
.and_then(|map| map.get("HP3"))
410+
.map(RpcValue::as_map)
411+
.and_then(|map| map.get("type"))
412+
.map(RpcValue::as_str)
413+
.is_none_or(|type_str| type_str != "HP3")
414+
{
415+
eprintln!("This site's _meta does NOT include an HP3 node. Refusing to continue. Add an HP3 node to the site's _meta, otherwise this HP instance will not be visible to parent HPs.");
416+
std::process::abort();
425417
}
418+
let sub_hps = collect_sub_hps(&[], &sites);
419+
let mut sites_info = collect_sites(&[], &sites);
420+
for (path, site_info) in &mut sites_info {
421+
if let Some((prefix, _)) = find_longest_path_prefix(&sub_hps, path) {
422+
site_info.sub_hp = prefix.into();
423+
} else {
424+
log::error!("Cannot find sub HP for site {path}");
425+
site_info.sub_hp = path.clone();
426+
}
427+
}
428+
break 'sites_get_loop (Arc::new(sites_info), Arc::new(sub_hps));
426429
}
427-
(Arc::new(sites_info), Arc::new(sub_hps))
428-
}
429-
Err(err) => match err.error() {
430-
CallRpcMethodErrorKind::ConnectionClosed => {
431-
log::warn!("Connection closed while getting sites info");
432-
continue
433-
}
434-
_ => {
435-
log::error!("Get sites info error: {err}");
436-
Default::default()
430+
Err(err) => {
431+
match err.error() {
432+
CallRpcMethodErrorKind::ConnectionClosed => {
433+
log::warn!("Connection closed while getting sites info");
434+
continue 'main_loop;
435+
}
436+
_ => {
437+
log::error!("Get sites info error: {err}");
438+
}
439+
}
440+
tokio::time::sleep(Duration::from_secs(1)).await;
437441
}
438442
}
439443
};

0 commit comments

Comments
 (0)