File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
1
from meilisearch .index import Index
2
2
from meilisearch .config import Config
3
3
from meilisearch ._httprequests import HttpRequests
4
- from meilisearch .errors import MeiliSearchApiError
4
+ from meilisearch .errors import MeiliSearchApiError , MeiliSearchError
5
5
6
6
class Client ():
7
7
"""
@@ -161,6 +161,21 @@ def health(self):
161
161
"""
162
162
return self .http .get (self .config .paths .health )
163
163
164
+ def is_healthy (self ):
165
+ """Get health of the MeiliSearch server.
166
+
167
+ `200` HTTP status response when MeiliSearch is healthy.
168
+
169
+ Return
170
+ ------
171
+ health: True | False
172
+ """
173
+ try :
174
+ self .health ()
175
+ except MeiliSearchError :
176
+ return False
177
+ return True
178
+
164
179
def get_keys (self ):
165
180
"""Get all keys.
166
181
Original file line number Diff line number Diff line change
1
+ import meilisearch
1
2
2
3
def test_health (client ):
3
4
"""Tests checking the health of the MeiliSearch instance."""
4
5
response = client .health ()
5
6
assert response ['status' ] == 'available'
7
+
8
+ def test_is_healthy (client ):
9
+ """Tests checking if is_healthy return true when MeiliSearch instance is available."""
10
+ response = client .is_healthy ()
11
+ assert response is True
12
+
13
+ def test_is_healthy_bad_route ():
14
+ """Tests checking if is_healthy returns false when trying to reach a bad URL."""
15
+ client = meilisearch .Client ("http://wrongurl:1234" )
16
+ response = client .is_healthy ()
17
+ assert response is False
You can’t perform that action at this time.
0 commit comments