From e1af58f56be80c7ca79b8e73e32f3dd59faab2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Provost?= Date: Wed, 12 Jul 2017 10:36:43 +0200 Subject: [PATCH] feat: Add support for the `/1/isalive` endpoint This endpoint does an application-level ping. It is only useful for diagnosis purposes, or to pre-establish a connection before running actual operations. --- algoliasearch/client.py | 7 +++++++ tests/test_client.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/algoliasearch/client.py b/algoliasearch/client.py index 837325bd9..1cc342150 100644 --- a/algoliasearch/client.py +++ b/algoliasearch/client.py @@ -534,6 +534,13 @@ def generate_secured_api_key(self, private_api_key, queryParameters, securedKey = hmac.new(private_api_key.encode('utf-8'), queryParameters.encode('utf-8'), hashlib.sha256).hexdigest() return str(base64.b64encode(("%s%s" % (securedKey, queryParameters)).encode('utf-8')).decode('utf-8')) + def is_alive(self): + """ + Test if the server is alive. + This performs a simple application-level ping. If up and running, the server answers with a basic message. + """ + return self._req(True, '/1/isalive', 'GET') + def _req(self, is_search, path, meth, params=None, data=None): if len(self.api_key) > MAX_API_KEY_LENGTH: if data is None: diff --git a/tests/test_client.py b/tests/test_client.py index 7678aeb3a..f4e0ad8a9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -147,6 +147,10 @@ def test_dns_timeout_hard(self): self.assertLess(time.time(), now + 6) + def test_is_alive(self): + res = self.client.is_alive() + self.assertIn('message', res) +