Skip to content

Commit

Permalink
Catch 409s in Beaker.experiment.stop
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Jun 13, 2024
1 parent 0cd67b2 commit 94a2aea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 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

### Fixed

- Raise `ExperimentConflict` when stopping an experiment that was already stopped from `Beaker.experiment.stop`.

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

### Added
Expand Down
2 changes: 1 addition & 1 deletion beaker/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ExperimentNotFound(NotFoundError):

class ExperimentConflict(BeakerError):
"""
Raised when attempting to create/rename an experiment if an experiment by that name already exists.
Raised when attempting to create/rename/stop an experiment that already exists or is already stopped.
"""


Expand Down
6 changes: 5 additions & 1 deletion beaker/services/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def stop(self, experiment: Union[str, Experiment]):
:param experiment: The experiment ID, name, or object.
:raises ExperimentNotFound: If the experiment can't be found.
:raises ExperimentConflict: If the experiment was already stopped.
:raises BeakerError: Any other :class:`~beaker.exceptions.BeakerError` type that can occur.
:raises RequestException: Any other exception that can occur when contacting the
Beaker server.
Expand All @@ -257,7 +258,10 @@ def stop(self, experiment: Union[str, Experiment]):
self.request(
f"experiments/{self.url_quote(experiment_id)}/stop",
method="PUT",
exceptions_for_status={404: ExperimentNotFound(self._not_found_err_msg(experiment))},
exceptions_for_status={
404: ExperimentNotFound(self._not_found_err_msg(experiment)),
409: ExperimentConflict("Experiment already stopped"),
},
)

def resume(self, experiment: Union[str, Experiment]):
Expand Down

0 comments on commit 94a2aea

Please sign in to comment.