Skip to content

Commit

Permalink
create dedicated client to avoid 'Service was not ready'
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Jan 9, 2025
1 parent 1d1c10e commit c89c142
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/qdrant_client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{Qdrant, QdrantError};
/// .compression(Some(CompressionEncoding::Gzip))
/// .build();
/// ```
#[derive(Clone)]
pub struct QdrantConfig {
/// Qdrant server URI to connect to
pub uri: String,
Expand Down
30 changes: 19 additions & 11 deletions src/qdrant_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@ impl Qdrant {
///
/// Constructs the client and connects based on the given [`QdrantConfig`](config::QdrantConfig).
pub fn new(config: QdrantConfig) -> QdrantResult<Self> {
let check_compatibility = config.check_compatibility;
let channel = ChannelPool::new(
config.uri.parse::<Uri>()?,
config.timeout,
config.connect_timeout,
config.keep_alive_while_idle,
);

let client = Self { channel, config };
if config.check_compatibility {
// create a temporary client to check compatibility
let channel = ChannelPool::new(
config.uri.parse::<Uri>()?,
config.timeout,
config.connect_timeout,
config.keep_alive_while_idle,
);
let client = Self { channel, config: config.clone() };

if check_compatibility {
// We're in sync context, spawn temporary runtime in thread to do async health check
let server_version = thread::scope(|s| {
s.spawn(|| {
Expand All @@ -120,7 +119,7 @@ impl Qdrant {
.block_on(client.health_check())
})
.join()
.unwrap()
.expect("Failed to join health check thread")
})
.ok()
.map(|info| info.version);
Expand All @@ -142,6 +141,15 @@ impl Qdrant {
}
}

let channel = ChannelPool::new(
config.uri.parse::<Uri>()?,
config.timeout,
config.connect_timeout,
config.keep_alive_while_idle,
);

let client = Self { channel, config };

Ok(client)
}

Expand Down

0 comments on commit c89c142

Please sign in to comment.