Skip to content

Commit 287d44a

Browse files
bors[bot]alallema
andauthored
Merge #124
124: Standardize health method r=curquiza a=alallema **Description** Checking that method `health()` return `{'status': 'available'}` and added `is_healthy()` method who return boolean value **Issue related** meilisearch/integration-guides#55 **Some points of concern** - I let `Health` struct like it was: ```rust #[derive(Deserialize)] pub struct Health { pub status: String, } ``` but I see we could write it this way too: ```rust #[derive(Deserialize)] #[serde(tag="status")] pub enum Health { #[serde(rename="available")] Available } ``` That's means API should return `'available'` and this could lead to more maintenance but it seemed to be more accurate. Co-authored-by: alallema <[email protected]> Co-authored-by: Amélie <[email protected]>
2 parents b2b6c66 + d9eb909 commit 287d44a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/client.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a> Client<'a> {
176176
/// # Example
177177
///
178178
/// ```
179-
/// # use meilisearch_sdk::{client::*, indexes::*, errors::{Error, ErrorCode}};
179+
/// # use meilisearch_sdk::{client::*, errors::{Error, ErrorCode}};
180180
/// #
181181
/// # futures::executor::block_on(async move {
182182
/// let client = Client::new("http://localhost:7700", "masterKey");
@@ -193,6 +193,27 @@ impl<'a> Client<'a> {
193193
.await
194194
}
195195

196+
/// Get health of MeiliSearch server, return true or false.
197+
///
198+
/// # Example
199+
///
200+
/// ```
201+
/// # use meilisearch_sdk::client::*;
202+
/// #
203+
/// # futures::executor::block_on(async move {
204+
/// let client = Client::new("http://localhost:7700", "masterKey");
205+
/// let health = client.is_healthy().await;
206+
/// assert_eq!(health, true);
207+
/// # });
208+
/// ```
209+
pub async fn is_healthy(&self) -> bool {
210+
if let Ok(health) = self.health().await {
211+
health.status.as_str() == "available"
212+
} else {
213+
false
214+
}
215+
}
216+
196217
/// Get the private and public key.
197218
///
198219
/// # Example

0 commit comments

Comments
 (0)