always get progress events
even if spawn finishes
produces more consistent output, fewer branches in the code
@@ -233,16 +233,15 @@ class Launcher(LoggingConfigurable):
# start server
app_log.info(f"Starting server{_server_name} for user {username} with image {image}")
+ ready_event_container = []
try:
resp = await self.api_request(
'users/{}/servers/{}'.format(escaped_username, server_name),
method='POST',
body=json.dumps(data).encode('utf8'),
)
- if resp.code == 202:
- # Server hasn't actually started yet
# listen for pending spawn (launch) events until server is ready
- ready_event_container = []
+ # do this even if previous request finished!
buffer_list = []
async def handle_chunk(chunk):
@@ -283,23 +282,23 @@ class Launcher(LoggingConfigurable):
f"Image {image} for user {username} took too long to launch",
)
- # verify that the server is running!
- if not ready_event_container:
- raise web.HTTPError(
- 500, f"Image {image} for user {username} failed to launch"
- )
-
except HTTPError as e:
if e.response:
body = e.response.body
else:
body = ''
- app_log.error("Error starting server{} for user {}: {}\n{}".
- format(_server_name, username, e, body))
+ app_log.error(
+ f"Error starting server{_server_name} for user {username}: {e}\n{body}"
+ )
raise web.HTTPError(500, f"Failed to launch image {image}")
- data["url"] = url_path_join(
- self.hub_url, f"user/{escaped_username}/{server_name}"
+ # verify that the server is running!
+ if not ready_event_container:
+ raise web.HTTPError(
+ 500, f"Image {image} for user {username} failed to launch"
)
+ ready_event = ready_event_container[0]
+
+ data["url"] = url_path_join(self.hub_url, ready_event["url"])
return data
