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/web.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/web.py')
-rw-r--r-- | fatcat_scholar/web.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py index 4887aa6..9664474 100644 --- a/fatcat_scholar/web.py +++ b/fatcat_scholar/web.py @@ -21,7 +21,7 @@ from starlette.exceptions import HTTPException as StarletteHTTPException from fatcat_scholar.config import settings, GIT_REVISION from fatcat_scholar.hacks import Jinja2Templates, parse_accept_lang -from fatcat_scholar.search import process_query, FulltextQuery, FulltextHits +from fatcat_scholar.search import process_query, FulltextQuery, FulltextHits, es_scholar_index_exists from fatcat_scholar.schema import ScholarDoc @@ -107,15 +107,17 @@ async def root_head() -> Any: return Response() @api.get("/_health", operation_id="get_health") -async def health() -> Any: +def health_get() -> Any: """ Checks that connection back to elasticsearch index is working. """ + if not es_scholar_index_exists(): + raise HTTPException(status_code=503) return Response() @api.head("/_health", include_in_schema=False) -async def health_head() -> Any: - return Response() +def health_head() -> Any: + return health_get() class HitsModel(BaseModel): count_returned: int |