Skip to content

Commit 67efc87

Browse files
committed
feat: add http api to get status
1 parent 3715c11 commit 67efc87

File tree

10 files changed

+576
-0
lines changed

10 files changed

+576
-0
lines changed

Cargo.lock

Lines changed: 244 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ socket2 = "0.6.1"
2828
notify = "7.0"
2929
tokio-util = "0.7.17"
3030
ctrlc2 = "3.7.3"
31+
axum = "0.7"
32+
tower = "0.4"
33+
tower-http = { version = "0.5", features = ["cors"] }
34+
once_cell = "1.20"
3135

3236
[dev-dependencies]
3337
tokio-test = "0.4"

src/client/http/cache.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Status cache management
2+
3+
use std::sync::Arc;
4+
use tokio::sync::RwLock;
5+
use super::models::StatusResponse;
6+
7+
/// Global status cache (shared between HTTP server and event loop)
8+
static STATUS_CACHE: once_cell::sync::Lazy<Arc<RwLock<Option<StatusResponse>>>> =
9+
once_cell::sync::Lazy::new(|| Arc::new(RwLock::new(None)));
10+
11+
/// Get a reference to the status cache
12+
pub fn get_cache() -> Arc<RwLock<Option<StatusResponse>>> {
13+
STATUS_CACHE.clone()
14+
}
15+
16+
/// Update the status cache (called from event loop)
17+
pub async fn update(status: StatusResponse) {
18+
let mut cache = STATUS_CACHE.write().await;
19+
*cache = Some(status);
20+
}
21+
22+
/// Get the current cached status
23+
pub async fn get() -> Option<StatusResponse> {
24+
let cache = STATUS_CACHE.read().await;
25+
cache.clone()
26+
}
27+

0 commit comments

Comments
 (0)