Skip to content

Commit f70a8f7

Browse files
committed
Health method return True now and adding is_healthy_method
1 parent 866e9e2 commit f70a8f7

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

meilisearch/client.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,26 @@ def health(self):
159159
MeiliSearchApiError
160160
An error containing details about why MeiliSearch can't process your request. MeiliSearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
161161
"""
162-
return self.http.get(self.config.paths.health)
162+
try:
163+
self.http.get(self.config.paths.health)
164+
except MeiliSearchApiError as err:
165+
raise err
166+
return True
167+
168+
def is_healthy(self):
169+
"""Get health of the MeiliSearch server.
170+
171+
`200` HTTP status response when MeiliSearch is healthy.
172+
173+
Return
174+
------
175+
health: True | False
176+
"""
177+
try:
178+
self.http.get(self.config.paths.health)
179+
except MeiliSearchApiError:
180+
return False
181+
return True
163182

164183
def get_keys(self):
165184
"""Get all keys.

meilisearch/tests/client/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ def test_get_client():
99
client = meilisearch.Client(BASE_URL, MASTER_KEY)
1010
assert client.config
1111
response = client.health()
12-
assert response['status'] == 'available'
12+
assert response is True
1313

1414

1515
def test_client_timeout_set():
1616
timeout = 5
1717
client = meilisearch.Client(BASE_URL, MASTER_KEY, timeout=timeout)
1818
response = client.health()
1919
assert client.config.timeout == timeout
20-
assert response['status'] == 'available'
20+
assert response is True
2121

2222

2323
def test_client_timeout_not_set():
2424
default_timeout = None
2525
client = meilisearch.Client(BASE_URL, MASTER_KEY)
2626
response = client.health()
2727
assert client.config.timeout == default_timeout
28-
assert response['status'] == 'available'
28+
assert response is True

meilisearch/tests/client/test_client_health_meilisearch.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
def test_health(client):
33
"""Tests checking the health of the MeiliSearch instance."""
44
response = client.health()
5-
assert response['status'] == 'available'
5+
assert response is True
6+
7+
def test_is_healthy(client):
8+
"""Tests checking the health of the MeiliSearch instance."""
9+
response = client.is_healthy()
10+
assert response is True

0 commit comments

Comments
 (0)