Skip to content

Commit

Permalink
Merge #246
Browse files Browse the repository at this point in the history
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 <amelie@meilisearch.com>
  • Loading branch information
bors[bot] and alallema authored Apr 15, 2021
2 parents 6cf5166 + 775d86b commit fdd55d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion meilisearch/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from meilisearch.index import Index
from meilisearch.config import Config
from meilisearch._httprequests import HttpRequests
from meilisearch.errors import MeiliSearchApiError
from meilisearch.errors import MeiliSearchApiError, MeiliSearchError

class Client():
"""
Expand Down Expand Up @@ -161,6 +161,21 @@ def health(self):
"""
return self.http.get(self.config.paths.health)

def is_healthy(self):
"""Get health of the MeiliSearch server.
`200` HTTP status response when MeiliSearch is healthy.
Return
------
health: True | False
"""
try:
self.health()
except MeiliSearchError:
return False
return True

def get_keys(self):
"""Get all keys.
Expand Down
12 changes: 12 additions & 0 deletions meilisearch/tests/client/test_client_health_meilisearch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import meilisearch

def test_health(client):
"""Tests checking the health of the MeiliSearch instance."""
response = client.health()
assert response['status'] == 'available'

def test_is_healthy(client):
"""Tests checking if is_healthy return true when MeiliSearch instance is available."""
response = client.is_healthy()
assert response is True

def test_is_healthy_bad_route():
"""Tests checking if is_healthy returns false when trying to reach a bad URL."""
client = meilisearch.Client("http://wrongurl:1234")
response = client.is_healthy()
assert response is False

0 comments on commit fdd55d9

Please sign in to comment.