diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-03-29 20:37:28 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-03-29 20:37:30 -0700 |
commit | b6ea443af3b1a304a964c19b45c4cbec9e751dc0 (patch) | |
tree | 200b88b420d802b558fa558f43cb6a30a3883971 /fatcat_scholar/search.py | |
parent | 93f1ccaafd2819501f856ac3594ea16d3b921896 (diff) | |
download | fatcat-scholar-b6ea443af3b1a304a964c19b45c4cbec9e751dc0.tar.gz fatcat-scholar-b6ea443af3b1a304a964c19b45c4cbec9e751dc0.zip |
web and API health check endpoint
Because scholar is primarily a search service, the endpoint does a
pass-through health check to the elasticsearch backend (aka,
es-public-proxy).
Diffstat (limited to 'fatcat_scholar/search.py')
-rw-r--r-- | fatcat_scholar/search.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index be362b7..026c030 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -415,3 +415,17 @@ def do_fulltext_search( query_wall_time_ms=int(query_delta.total_seconds() * 1000), results=results, ) + +def es_scholar_index_exists() -> bool: + """ + Checks if the configured back-end elasticsearch index exists. + Intended to be used in health checks. + """ + try: + resp = es_client.indices.exists(settings.ELASTICSEARCH_QUERY_FULLTEXT_INDEX) + except elasticsearch.exceptions.RequestError as e_raw: + if e_raw.status_code == 404: + return False + else: + raise e_raw + return resp |