diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-20 15:13:12 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-20 15:13:12 +0200 |
| commit | 1594307d9cd819b1ed739fa1ec048c6b27e6f4b0 (patch) | |
| tree | 39b427e3cd6390bc218136454b809450016e0037 /crates/daemon/src/api/client/mod.rs | |
| parent | chore: Commit (diff) | |
| download | atuin-1594307d9cd819b1ed739fa1ec048c6b27e6f4b0.zip | |
chore: Commit
Diffstat (limited to 'crates/daemon/src/api/client/mod.rs')
| -rw-r--r-- | crates/daemon/src/api/client/mod.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/crates/daemon/src/api/client/mod.rs b/crates/daemon/src/api/client/mod.rs index d6cbbe85..71fa0e37 100644 --- a/crates/daemon/src/api/client/mod.rs +++ b/crates/daemon/src/api/client/mod.rs @@ -64,10 +64,37 @@ pub fn classify_error(error: &eyre::Report) -> DaemonClientErrorKind { DaemonClientErrorKind::Other } +#[derive(Debug)] +pub enum Probe { + Ready(ControlClient), + NeedsRestart(String), + Unreachable(eyre::Report), +} + +/// Check if a client can reach the daemon. +pub async fn probe(path: String) -> Probe { + let mut client = match ControlClient::new(path).await { + Ok(client) => client, + Err(err) => return Probe::Unreachable(err), + }; + + match client.status().await { + Ok(status) => { + if daemon_matches_expected(&status.version, status.protocol) { + Probe::Ready(client) + } else { + Probe::NeedsRestart(daemon_mismatch_message(&status.version, status.protocol)) + } + } + Err(err) => Probe::Unreachable(err), + } +} + // ============================================================================ // History Client // ============================================================================ +#[derive(Debug)] pub struct HistoryClient { client: HistoryServiceClient<Channel>, } @@ -139,13 +166,14 @@ impl HistoryClient { // ============================================================================ /// Client for the Control gRPC service. +#[derive(Debug)] pub struct ControlClient { client: ControlServiceClient<Channel>, } impl ControlClient { /// Connect to the daemon's control service. - pub(crate) async fn new(path: String) -> Result<Self> { + pub async fn new(path: String) -> Result<Self> { let log_path = path.clone(); let channel = Endpoint::try_from("http://atuin_local_daemon:0")? .connect_with_connector(service_fn(move |_: Uri| { |
