Skip to content

Commit cbf1b41

Browse files
committed
Add healthcheck and sessions endpoints.
1 parent bae6c2e commit cbf1b41

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tiatoolbox/visualization/tileserver.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def __init__( # noqa: PLR0915
165165
self.route("/tileserver/tap_query/<x>/<y>")(self.tap_query)
166166
self.route("/tileserver/prop_range", methods=["PUT"])(self.prop_range)
167167
self.route("/tileserver/shutdown", methods=["POST"])(self.shutdown)
168+
self.route("/tileserver/sessions", methods=["GET"])(self.sessions)
169+
self.route("/tileserver/healthcheck", methods=["GET"])(self.healthcheck)
168170

169171
def _get_session_id(self: TileServer) -> str:
170172
"""Get the session_id from the request.
@@ -718,6 +720,30 @@ def prop_range(self: TileServer) -> str:
718720
self.renderers[session_id].score_fn = lambda x: (x - minv) / (maxv - minv)
719721
return "done"
720722

723+
def sessions(self: TileServer) -> Response:
724+
"""Retrieve a mapping of session keys to their corresponding slide file paths.
725+
726+
Returns:
727+
Response: A JSON response containing a mapping of session keys
728+
and their respective slide file paths.
729+
"""
730+
session_paths = {}
731+
for key, layer in self.layers.items():
732+
session_paths[key] = str(layer.get("slide").info.as_dict()["file_path"])
733+
734+
return jsonify(session_paths)
735+
736+
def healthcheck(self: TileServer) -> Response:
737+
"""Simple health check endpoint to verify the server is running.
738+
739+
Useful for load balancers or uptime monitoring tools to check
740+
if the service is operational.
741+
742+
Returns:
743+
Response: A JSON response with status "OK" and HTTP status code 200.
744+
"""
745+
return jsonify({"status": "OK"})
746+
721747
@staticmethod
722748
def shutdown() -> None:
723749
"""Shutdown the tileserver."""

tiatoolbox/visualization/tileserver_api.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,24 @@ paths:
395395
'200':
396396
description: Successful response
397397

398+
/tileserver/sessions:
399+
get:
400+
summary: Returns all session/path mappings
401+
responses:
402+
'200':
403+
description: A jsonified session/path mappings
404+
content:
405+
application/json:
406+
407+
/tileserver/healthcheck:
408+
get:
409+
summary: Returns Ok if server is online
410+
responses:
411+
'200':
412+
description: A json with status field
413+
content:
414+
application/json:
415+
398416
/tileserver/tap_query/{x}/{y}:
399417
get:
400418
summary: Query annotation at a point

0 commit comments

Comments
 (0)