Skip to content

Commit ee79a1d

Browse files
committed
Add last_sites_loaded
1 parent c80525d commit ee79a1d

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub struct State {
100100
sync_cmd_tx: DedupSender<sync::SyncCommand>,
101101
dirtylog_cmd_tx: UnboundedSender<dirtylog::DirtyLogCommand>,
102102
app_closing: AtomicBool,
103+
last_sites_loaded: RwLock<Option<std::time::Instant>>,
103104
}
104105

105106
#[derive(Default)]
@@ -148,6 +149,7 @@ pub fn make_client(hp_config: &HpConfig, tasks: &mut AppTasks) -> shvrpc::Result
148149
sync_cmd_tx,
149150
dirtylog_cmd_tx,
150151
app_closing: AtomicBool::new(false),
152+
last_sites_loaded: RwLock::new(None),
151153
});
152154

153155
let client = shvclient::Client::new()

src/sites.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ pub(crate) async fn sites_task(
638638
.unbounded_send(PeriodicSyncCommand::Enable)
639639
.unwrap_or_else(|e| log::error!("Cannot send periodic sync enable command: {e}"));
640640

641+
*app_state.last_sites_loaded.write().await = Some(std::time::Instant::now());
641642
},
642643
Event::ClientEvent(ClientEvent::Disconnected) | Event::ClientEvent(ClientEvent::ConnectionFailed(_)) => {
643644
subscribers.clear();

src/tree.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const META_METHOD_PUSH_LOG: MetaMethod = MetaMethod::new_static(METH_PUSH_LOG, s
4949
const METH_VERSION: &str = "version";
5050
const METH_UPTIME: &str = "uptime";
5151
const METH_RELOAD_SITES: &str = "reloadSites";
52+
const METH_LAST_SITES_LOADED: &str = "lastSitesLoaded";
5253

5354
// File nodes methods
5455
const METH_HASH: &str = "hash";
@@ -615,6 +616,7 @@ pub(crate) async fn request_handler(
615616
MetaMethod::new_static(METH_VERSION, shvrpc::metamethod::Flags::None, AccessLevel::Read, "Null", "String", &[], ""),
616617
MetaMethod::new_static(METH_UPTIME, shvrpc::metamethod::Flags::None, AccessLevel::Read, "Null", "String", &[], ""),
617618
MetaMethod::new_static(METH_RELOAD_SITES, shvrpc::metamethod::Flags::None, AccessLevel::Write, "Null", "Bool", &[], ""),
619+
MetaMethod::new_static(METH_LAST_SITES_LOADED, shvrpc::metamethod::Flags::None, AccessLevel::Read, "Null", "DateTime", &[], ""),
618620
META_METHOD_ALARM_LOG,
619621
// TODO: All root node methods:
620622
// appName
@@ -654,6 +656,9 @@ pub(crate) async fn request_handler(
654656
sites_cmd_tx.unbounded_send(crate::sites::SitesCommand::ReloadSites).map_err(|err| RpcError::new(RpcErrorCode::InternalError, format!("Couldn't reload sites: {err}")))?;
655657
Ok("Sites queued for a reload. This might take a while.".to_string())
656658
}),
659+
METH_LAST_SITES_LOADED => m.resolve(METHODS, async move || {
660+
Ok(app_state.last_sites_loaded.read().await.map(|last_sites_loaded| humantime::format_duration(std::time::Duration::from_secs(last_sites_loaded.elapsed().as_secs())).to_string()))
661+
}),
657662
_ => err_unresolved_request(),
658663
}
659664
}

0 commit comments

Comments
 (0)