Skip to content

Commit fdd55d9

Browse files
bors[bot]alallema
andauthored
Merge #246
246: Standardize health method r=bidoubiwa a=alallema Checking that method health() return `{'status': 'available'}` and added isHealthy() method who return boolean value meilisearch/integration-guides#55 Co-authored-by: alallema <[email protected]>
2 parents 6cf5166 + 775d86b commit fdd55d9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: meilisearch/client.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from meilisearch.index import Index
22
from meilisearch.config import Config
33
from meilisearch._httprequests import HttpRequests
4-
from meilisearch.errors import MeiliSearchApiError
4+
from meilisearch.errors import MeiliSearchApiError, MeiliSearchError
55

66
class Client():
77
"""
@@ -161,6 +161,21 @@ def health(self):
161161
"""
162162
return self.http.get(self.config.paths.health)
163163

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+
164179
def get_keys(self):
165180
"""Get all keys.
166181
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
import meilisearch
12

23
def test_health(client):
34
"""Tests checking the health of the MeiliSearch instance."""
45
response = client.health()
56
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

0 commit comments

Comments
 (0)