Skip to content

Commit

Permalink
Add Job.execution_results (#282)
Browse files Browse the repository at this point in the history
* Add `Job.execution_results`

Fixes #281.

* hack the right status code
  • Loading branch information
epwalsh authored Jul 8, 2024
1 parent 09694d6 commit 9926184
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use patch releases for compatibility fixes instead.

## Unreleased

### Added

- Added `execution_results` to `Job` model.

## [v1.30.0](https://github.com/allenai/beaker-py/releases/tag/v1.30.0) - 2024-06-14

### Added
Expand Down
3 changes: 2 additions & 1 deletion beaker/data_model/job.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union

from pydantic import Field

Expand Down Expand Up @@ -175,6 +175,7 @@ class Job(BaseModel):
name: Optional[str] = None
cluster: Optional[str] = None
execution: Optional[JobExecution] = None
execution_results: Optional[Dict[str, Any]] = None
node: Optional[str] = None
requests: Optional[JobRequests] = None
limits: Optional[JobLimits] = None
Expand Down
21 changes: 12 additions & 9 deletions beaker/services/service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def make_request(session: requests.Session) -> requests.Response:
else:
self.logger.debug("RECV %s %s %s", method, url, response)

if exceptions_for_status is not None and response.status_code in exceptions_for_status:
raise exceptions_for_status[response.status_code]
status_code = response.status_code

try:
response.raise_for_status()
Expand All @@ -119,16 +118,20 @@ def make_request(session: requests.Session) -> requests.Response:
except (TypeError, KeyError, json.JSONDecodeError):
pass

if (
msg is not None
and response.status_code is not None
and 400 <= response.status_code < 500
):
# HACK: sometimes Beaker doesn't use the right error code, so we try to guess based
# on the message.
if status_code == 400 and msg is not None and "already in use" in msg:
status_code = 409

if exceptions_for_status is not None and status_code in exceptions_for_status:
raise exceptions_for_status[status_code]

if msg is not None and status_code is not None and 400 <= status_code < 500:
# Raise a BeakerError if we're misusing the API (4xx error code).
if response.status_code == 403:
if status_code == 403:
raise BeakerPermissionsError(msg)
else:
raise BeakerError(msg)
raise BeakerError(f"[code={status_code}] {msg}")
elif msg is not None:
raise HTTPError(msg, response=response) # type: ignore
else:
Expand Down

0 comments on commit 9926184

Please sign in to comment.