Skip to content

Commit 22051d5

Browse files
authored
Add health check (#70)
This commit adds a /health endpoint
1 parent e787cc9 commit 22051d5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

python/restate/server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ async def send_discovery(scope: Scope, send: Send, endpoint: Endpoint):
6565
'more_body': False,
6666
})
6767

68+
async def send_health_check(send: Send):
69+
"""respond with an health check"""
70+
headers = header_to_binary([("content-type", "application/json")])
71+
headers.extend(X_RESTATE_SERVER)
72+
await send({
73+
'type': 'http.response.start',
74+
'status': 200,
75+
'headers': headers,
76+
'trailers': False
77+
})
78+
await send({
79+
'type': 'http.response.body',
80+
'body': b'{"status":"ok"}',
81+
'more_body': False,
82+
})
83+
6884
async def process_invocation_to_completion(vm: VMWrapper,
6985
handler,
7086
attempt_headers: Dict[str, str],
@@ -135,6 +151,11 @@ async def app(scope: Scope, receive: Receive, send: Send):
135151
request_path = scope['path']
136152
assert isinstance(request_path, str)
137153

154+
# Health check
155+
if request_path == '/health':
156+
await send_health_check(send)
157+
return
158+
138159
# Verify Identity
139160
assert not isinstance(scope['headers'], str)
140161
assert hasattr(scope['headers'], '__iter__')

0 commit comments

Comments
 (0)