Skip to content

Commit

Permalink
Add support for the new "cancelling" invocation state
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Nov 23, 2023
1 parent 49930ac commit 9eb2e3a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Classes defined in ``bioblend.galaxy.objects.wrappers`` are no more
re-exported by ``bioblend.galaxy.objects``.

* Added support for the new "cancelling" invocation state.

### BioBlend v1.2.0 - 2023-06-30

* Dropped support for Galaxy releases 17.09-19.01. Added support for Galaxy
Expand Down
31 changes: 17 additions & 14 deletions bioblend/_tests/TestGalaxyInvocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ def setUp(self):
self.workflow_id = self.gi.workflows.import_workflow_from_local_path(path)["id"]
self.history_id = self.gi.histories.create_history(name="TestGalaxyInvocations")["id"]
self.dataset_id = self._test_dataset(self.history_id)
path = test_util.get_abspath(os.path.join("data", "test_workflow_pause.ga"))
self.pause_workflow_id = self.gi.workflows.import_workflow_from_local_path(path)["id"]

def tearDown(self):
self.gi.histories.delete_history(self.history_id, purge=True)

@test_util.skip_unless_galaxy("release_19.09")
def test_cancel_invocation(self):
invocation = self._invoke_workflow()

invocation = self._invoke_pause_workflow()
invocation_id = invocation["id"]
invocations = self.gi.invocations.get_invocations()
assert len(invocations) == 1
assert invocations[0]["id"] == invocation_id
self.gi.invocations.cancel_invocation(invocation_id)
assert invocation_id in [inv["id"] for inv in invocations]

invocation = self.gi.invocations.show_invocation(invocation_id)
assert invocation["state"] == "cancelled"
assert invocation["state"] in ["new", "ready"]

invocation = self.gi.invocations.cancel_invocation(invocation_id)
assert invocation["state"] in ["cancelled", "cancelling"]

@test_util.skip_unless_galaxy("release_20.01")
def test_get_invocations(self):
Expand Down Expand Up @@ -111,14 +114,7 @@ def test_get_invocation_jobs_summary(self):
@test_util.skip_unless_tool("cat1")
@test_util.skip_unless_tool("cat")
def test_workflow_scheduling(self):
path = test_util.get_abspath(os.path.join("data", "test_workflow_pause.ga"))
workflow = self.gi.workflows.import_workflow_from_local_path(path)

invocation = self.gi.workflows.invoke_workflow(
workflow["id"],
inputs={"0": {"src": "hda", "id": self.dataset_id}},
history_id=self.history_id,
)
invocation = self._invoke_pause_workflow()
invocation_id = invocation["id"]

def invocation_steps_by_order_index() -> Dict[int, Dict[str, Any]]:
Expand Down Expand Up @@ -154,3 +150,10 @@ def _invoke_workflow(self) -> Dict[str, Any]:
history_id=self.history_id,
inputs_by="name",
)

def _invoke_pause_workflow(self) -> Dict[str, Any]:
return self.gi.workflows.invoke_workflow(
self.pause_workflow_id,
inputs={"0": {"src": "hda", "id": self.dataset_id}},
history_id=self.history_id,
)
2 changes: 1 addition & 1 deletion bioblend/_tests/TestGalaxyObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def test_sorted_steps_by(self):
def test_cancel(self):
inv = self._obj_invoke_workflow()
inv.cancel()
assert inv.state == "cancelled"
assert inv.state in ["cancelled", "cancelling"]

def test_wait(self):
inv = self._obj_invoke_workflow()
Expand Down
10 changes: 4 additions & 6 deletions bioblend/_tests/TestGalaxyWorkflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,18 @@ def test_cancelling_workflow_scheduling(self):
assert len(invocations) == 0

invocation = self.gi.workflows.invoke_workflow(
workflow["id"],
workflow_id,
inputs={"0": {"src": "hda", "id": dataset1_id}},
)
invocation_id = invocation["id"]
invocations = self.gi.workflows.get_invocations(workflow_id)
assert len(invocations) == 1
assert invocations[0]["id"] == invocation_id
assert invocation_id in [inv["id"] for inv in invocations]

invocation = self.gi.workflows.show_invocation(workflow_id, invocation_id)
assert invocation["state"] in ["new", "ready"]

self.gi.workflows.cancel_invocation(workflow_id, invocation_id)
invocation = self.gi.invocations.wait_for_invocation(invocation_id, check=False)
assert invocation["state"] == "cancelled"
invocation = self.gi.workflows.cancel_invocation(workflow_id, invocation_id)
assert invocation["state"] in ["cancelled", "cancelling"]

def test_import_export_workflow_from_local_path(self):
with pytest.raises(TypeError):
Expand Down
2 changes: 1 addition & 1 deletion bioblend/galaxy/invocations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
log = logging.getLogger(__name__)

INVOCATION_TERMINAL_STATES = {"cancelled", "failed", "scheduled"}
# Invocation non-terminal states are: 'new', 'ready'
# Invocation non-terminal states are: "cancelling", "new", "ready"


class InvocationClient(Client):
Expand Down

0 comments on commit 9eb2e3a

Please sign in to comment.