Skip to content

Commit 15d3455

Browse files
committed
fix health check issue
1 parent dd9de99 commit 15d3455

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ dmypy.json
132132

133133
# Pyre type checker
134134
.pyre/
135+
136+
# Mac DS_Store
137+
.DS_Store

fastdeploy/_app.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -303,23 +303,27 @@ def on_get(self, req, resp):
303303
class Health(object):
304304
def on_get(self, req, resp):
305305
stuck_for = float(req.params.get("stuck"))
306-
predictor_wait_started_at = _utils.META_INDEX["predictor_wait_started_at"]
307-
308-
if (
309-
stuck_for
310-
and predictor_wait_started_at
311-
and time.time() - predictor_wait_started_at >= stuck_for
312-
):
313-
resp.status = falcon.HTTP_503
314-
resp.media = {
315-
"predictor_status": f"predictor stuck for {time.time() - predictor_wait_started_at}. deemed stuck."
316-
}
306+
last_prediction_loop_start_time = _utils.META_INDEX["last_prediction_loop_start_time"]
307+
prediction_loop_stuck_for = time.time() - last_prediction_loop_start_time
308+
309+
if last_prediction_loop_start_time:
310+
if (
311+
stuck_for
312+
and prediction_loop_stuck_for >= stuck_for
313+
):
314+
resp.status = falcon.HTTP_503
315+
resp.media = {
316+
"predictor_status": f"prediction loop stuck for {prediction_loop_stuck_for}. deemed stuck."
317+
}
318+
else:
319+
resp.status = falcon.HTTP_200
320+
resp.media = {
321+
"predictor_status": f"prediction loop running for {prediction_loop_stuck_for}"
322+
}
317323
else:
318324
resp.status = falcon.HTTP_200
319325
resp.media = {
320-
"predictor_status": f"queue waiting for predictor for {time.time() - predictor_wait_started_at}"
321-
if predictor_wait_started_at
322-
else "queue empty"
326+
"predictor_status": f"prediction loop not started"
323327
}
324328

325329

fastdeploy/_loop.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
def start_loop():
13+
_utils.META_INDEX["last_prediction_loop_start_time"] = 0
14+
1315
ACCEPTS_EXTRAS = False
1416
try:
1517
from predictor import predictor
@@ -64,7 +66,8 @@ def start_loop():
6466
first_sleep_start_time = 0
6567
__loop_is_sleeping = False
6668
while True:
67-
_utils.META_INDEX["predictor_wait_started_at"] = 0
69+
_utils.META_INDEX["last_prediction_loop_start_time"] = time.time()
70+
6871
if len(_utils.REQUEST_INDEX):
6972
(
7073
unique_id,
@@ -125,7 +128,6 @@ def start_loop():
125128
try:
126129
pred_start_time = time.time()
127130
__in_batch_length = len(batch)
128-
_utils.META_INDEX["predictor_wait_started_at"] = time.time()
129131

130132
if ACCEPTS_EXTRAS:
131133
preds = predictor(
@@ -134,8 +136,6 @@ def start_loop():
134136
else:
135137
preds = predictor(batch, batch_size=batch_size)
136138

137-
_utils.META_INDEX["predictor_wait_started_at"] = 0
138-
139139
if not isinstance(preds, list) or len(preds) != __in_batch_length:
140140
_utils.logger.error(
141141
"Something is seriously wrong! len(inputs) != len(outputs) from predictor.py. Check your recipe"

0 commit comments

Comments
 (0)