Skip to content

Commit

Permalink
Drop the outcome suffix for clariry and specify a status code for the…
Browse files Browse the repository at this point in the history
… http error

Co-authored-by: Min RK <[email protected]>
  • Loading branch information
GeorgianaElena and minrk committed Oct 10, 2023
1 parent 6252eb6 commit 114b195
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions binderhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ def _template_path_default(self):
- /build/([^/]+)/(.+)
- /health
- /_config
- /* -> shows a 404 page
""",
config=True,
)
Expand Down
19 changes: 10 additions & 9 deletions binderhub/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,24 @@ def set_default_headers(self):
self.set_header("content-type", "text/event-stream")
self.set_header("cache-control", "no-cache")

def _get_build_only_outcome(self):
def _get_build_only(self):
# Get the value of the `enable_api_only_mode` traitlet
enable_api_only_mode = self.settings.get("enable_api_only_mode", False)
# Get the value of the `build_only` query parameter if present
build_only_query_parameter = str(
self.get_query_argument(name="build_only", default="")
)
build_only_outcome = False
build_only = False
if build_only_query_parameter.lower() == "true":
if not enable_api_only_mode:
raise HTTPError(
status_code=400,
log_message="Building but not launching is not permitted when"
" the API only mode was not enabled by setting `enable_api_only_mode` to True. "
)
build_only_outcome = True
build_only = True

return build_only_outcome
return build_only

@authenticated
async def get(self, provider_prefix, _unescaped_spec):
Expand Down Expand Up @@ -426,8 +427,8 @@ async def get(self, provider_prefix, _unescaped_spec):
else:
image_found = True

build_only_outcome = self._get_build_only_outcome()
if build_only_outcome:
build_only = self._get_build_only()
if build_only:
await self.emit(
{
"phase": "info",
Expand All @@ -437,7 +438,7 @@ async def get(self, provider_prefix, _unescaped_spec):
}
)
if image_found:
if build_only_outcome:
if build_only:
await self.emit(
{
"phase": "ready",
Expand Down Expand Up @@ -549,7 +550,7 @@ def _check_result(future):
# nothing to do, just waiting
continue
elif progress.payload == ProgressEvent.BuildStatus.BUILT:
if build_only_outcome:
if build_only:
message = "Done! Image built\n"
phase = "ready"
else:
Expand Down Expand Up @@ -598,7 +599,7 @@ def _check_result(future):
).inc()
await self.emit(event)

if build_only_outcome:
if build_only:
return

if not failed:
Expand Down

0 comments on commit 114b195

Please sign in to comment.