File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1313team_id = " 460355b3-4f64-48f9-9a16-4442817f79f5"
1414memory_mb = 1_024
1515start_cmd = " /root/.jupyter/start-up.sh"
16+ ready_cmd = " curl -s -o /dev/null -w '200' http://localhost:49999/health | grep -q '200'"
1617dockerfile = " e2b.Dockerfile"
1718template_name = " code-interpreter-v1"
1819template_id = " nlhz8vlwyupq845jsdg9"
Original file line number Diff line number Diff line change @@ -65,7 +65,17 @@ async def lifespan(app: FastAPI):
6565
6666@app .get ("/health" )
6767async def get_health ():
68- return "OK"
68+ websockets_ready = True
69+ for ws in default_websockets .values ():
70+ if not ws in websockets or not websockets [ws ].is_connected ():
71+ websockets_ready = False
72+ print (f"Context { ws } is not connected" )
73+ break
74+
75+ if not websockets_ready :
76+ return PlainTextResponse ("Not ready" , status_code = 503 )
77+
78+ return PlainTextResponse ("OK" , status_code = 200 )
6979
7080
7181@app .post ("/execute" )
Original file line number Diff line number Diff line change @@ -542,6 +542,10 @@ async def _process_message(self, data: dict):
542542 else :
543543 logger .warning (f"[UNHANDLED MESSAGE TYPE]: { data ['msg_type' ]} " )
544544
545+ def is_connected (self ) -> bool :
546+ """Check if the websocket is connected and open"""
547+ return self ._ws is not None and self ._ws .open
548+
545549 async def close (self ):
546550 logger .debug (f"Closing WebSocket { self .context_id } " )
547551
You can’t perform that action at this time.
0 commit comments