diff options
Diffstat (limited to '')
| -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| { |
