Skip to content

Commit

Permalink
Do async health check in sync context
Browse files Browse the repository at this point in the history
  • Loading branch information
timvisee committed Jan 7, 2025
1 parent f734d58 commit 3b53ff7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ serde = { version = "1.0.210", features = ["derive"], optional = true }
serde_json = { version = "1.0.128", optional = true }
reqwest = { version = "0.12.8", optional = true, default-features = false, features = ["stream", "rustls-tls", "http2"] }
futures = { version = "0.3.31" }
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
futures-util = { version = "0.3.31", optional = true }
derive_builder = { version = "0.20.2" }
thiserror = "1.0.64"

[dev-dependencies]
tonic-build = { version = "0.12.3", features = ["prost"] }
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }

[features]
default = ["download_snapshots", "serde", "generate-snippets"]
Expand Down
30 changes: 18 additions & 12 deletions src/qdrant_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod version_check;

use std::future::Future;

use futures::executor::block_on;
use tonic::codegen::InterceptedService;
use tonic::transport::{Channel, Uri};
use tonic::Status;
Expand Down Expand Up @@ -109,24 +108,31 @@ impl Qdrant {
let client = Self { channel, config };

if check_compatibility {
let client_version = env!("CARGO_PKG_VERSION").to_string();
let server_version = match block_on(async { client.health_check().await }) {
Ok(server_info) => server_info.version,
Err(_) => "Unknown".to_string(),
let health_check_future = client.health_check();

// Run future on current or new runtime depending on current context
let server_version = match tokio::runtime::Handle::try_current() {
Ok(_) => futures::executor::block_on(health_check_future),
Err(_) => tokio::runtime::Runtime::new()
.unwrap()
.block_on(health_check_future),
};
if server_version == "Unknown" {
println!(
"Failed to obtain server version. \
Unable to check client-server compatibility. \
Set check_compatibility=false to skip version check."
);
} else {
let server_version = server_version.map(|info| info.version).ok();

let client_version = env!("CARGO_PKG_VERSION").to_string();
if let Some(server_version) = server_version {
let is_compatible = is_compatible(Some(&client_version), Some(&server_version));
if !is_compatible {
println!("Client version {client_version} is not compatible with server version {server_version}. \
Major versions should match and minor version difference must not exceed 1. \
Set check_compatibility=false to skip version check.");
}
} else {
println!(
"Failed to obtain server version. \
Unable to check client-server compatibility. \
Set check_compatibility=false to skip version check."
);
}
}

Expand Down

0 comments on commit 3b53ff7

Please sign in to comment.