Loading src/nova/galaxy/job.py +8 −7 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ class Job: self.wait_for_results() except Exception as e: self.url = None if self.status.state == WorkState.STOPPING or self.status.state == WorkState.CANCELED: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING, WorkState.CANCELED]: self.status.state = WorkState.CANCELED return self.status.state = WorkState.ERROR Loading Loading @@ -116,7 +116,7 @@ class Job: for param, val in ids.items(): tool_inputs.set_dataset_param(param, val) if self.status.state == WorkState.STOPPING: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING]: self.status.state = WorkState.CANCELED return # Run tool and wait for job to finish Loading @@ -135,7 +135,7 @@ class Job: history_id = galaxy_instance.histories.get_histories(name=self.store.name)[0]["id"] dataset_ids: Dict[str, str] = {} for name, dataset in datasets.items(): if self.status.state == WorkState.STOPPING: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING]: self.cleanup_datasets(dataset_ids) return None if len(dataset.path) < 1 and dataset.get_content(): Loading @@ -148,7 +148,7 @@ class Job: dataset.id = dataset_info["outputs"][0]["id"] dataset.store = self.store for dataset_output in dataset_ids.values(): if self.status.state == WorkState.STOPPING: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING]: self.cleanup_datasets(dataset_ids) return None dataset_client.wait_for_dataset(dataset_output) Loading @@ -160,11 +160,12 @@ class Job: for dataset_id in datasets.values(): galaxy_instance.histories.delete_dataset(history_id=history_id, dataset_id=dataset_id, purge=True) def cancel(self, check_results: bool = False) -> bool: def cancel(self, stop: bool = False) -> bool: """Cancels or stops a job in Galaxy.""" self.url = None self.status.state = WorkState.CANCELING if stop: self.status.state = WorkState.STOPPING if check_results: response = self.galaxy_instance.make_put_request( f"{self.store.nova_connection.galaxy_url}/api/jobs/{self.id}/finish" ) Loading src/nova/galaxy/tool.py +2 −2 Original line number Diff line number Diff line Loading @@ -139,12 +139,12 @@ class Tool(AbstractWork): def stop(self) -> None: """Stop the tool, but keep any existing results.""" if self._job: self._job.cancel(check_results=True) self._job.cancel(stop=True) def cancel(self) -> None: """Cancels the tool execution and gets rid of any results collected.""" if self._job: self._job.cancel(check_results=False) self._job.cancel(stop=False) def get_stdout(self, position: Optional[int] = None, length: Optional[int] = None) -> Optional[str]: """Get the current STDOUT for a tool. Loading src/nova/galaxy/util.py +1 −0 Original line number Diff line number Diff line Loading @@ -15,3 +15,4 @@ class WorkState(Enum): DELETED = "deleted" CANCELED = "canceled" STOPPING = "stopping" CANCELING = "canceling" tests/test_run_tool.py +2 −2 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ def test_cancel_tool(nova_instance: Connection) -> None: test_tool.run_interactive(data_store=store, params=params, check_url=False) test_tool.cancel() state = test_tool.get_status() assert state == WorkState.STOPPING assert state == WorkState.CANCELING def test_cancel_tool_while_uploading(nova_instance: Connection, galaxy_instance: GalaxyInstance) -> None: Loading @@ -112,7 +112,7 @@ def test_cancel_tool_while_uploading(nova_instance: Connection, galaxy_instance: assert state == WorkState.UPLOADING_DATA test_tool.cancel() state = test_tool.get_status() assert state == WorkState.STOPPING assert state == WorkState.CANCELING test_tool.wait_for_results() state = test_tool.get_status() assert state == WorkState.CANCELED Loading Loading
src/nova/galaxy/job.py +8 −7 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ class Job: self.wait_for_results() except Exception as e: self.url = None if self.status.state == WorkState.STOPPING or self.status.state == WorkState.CANCELED: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING, WorkState.CANCELED]: self.status.state = WorkState.CANCELED return self.status.state = WorkState.ERROR Loading Loading @@ -116,7 +116,7 @@ class Job: for param, val in ids.items(): tool_inputs.set_dataset_param(param, val) if self.status.state == WorkState.STOPPING: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING]: self.status.state = WorkState.CANCELED return # Run tool and wait for job to finish Loading @@ -135,7 +135,7 @@ class Job: history_id = galaxy_instance.histories.get_histories(name=self.store.name)[0]["id"] dataset_ids: Dict[str, str] = {} for name, dataset in datasets.items(): if self.status.state == WorkState.STOPPING: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING]: self.cleanup_datasets(dataset_ids) return None if len(dataset.path) < 1 and dataset.get_content(): Loading @@ -148,7 +148,7 @@ class Job: dataset.id = dataset_info["outputs"][0]["id"] dataset.store = self.store for dataset_output in dataset_ids.values(): if self.status.state == WorkState.STOPPING: if self.status.state in [WorkState.STOPPING, WorkState.CANCELING]: self.cleanup_datasets(dataset_ids) return None dataset_client.wait_for_dataset(dataset_output) Loading @@ -160,11 +160,12 @@ class Job: for dataset_id in datasets.values(): galaxy_instance.histories.delete_dataset(history_id=history_id, dataset_id=dataset_id, purge=True) def cancel(self, check_results: bool = False) -> bool: def cancel(self, stop: bool = False) -> bool: """Cancels or stops a job in Galaxy.""" self.url = None self.status.state = WorkState.CANCELING if stop: self.status.state = WorkState.STOPPING if check_results: response = self.galaxy_instance.make_put_request( f"{self.store.nova_connection.galaxy_url}/api/jobs/{self.id}/finish" ) Loading
src/nova/galaxy/tool.py +2 −2 Original line number Diff line number Diff line Loading @@ -139,12 +139,12 @@ class Tool(AbstractWork): def stop(self) -> None: """Stop the tool, but keep any existing results.""" if self._job: self._job.cancel(check_results=True) self._job.cancel(stop=True) def cancel(self) -> None: """Cancels the tool execution and gets rid of any results collected.""" if self._job: self._job.cancel(check_results=False) self._job.cancel(stop=False) def get_stdout(self, position: Optional[int] = None, length: Optional[int] = None) -> Optional[str]: """Get the current STDOUT for a tool. Loading
src/nova/galaxy/util.py +1 −0 Original line number Diff line number Diff line Loading @@ -15,3 +15,4 @@ class WorkState(Enum): DELETED = "deleted" CANCELED = "canceled" STOPPING = "stopping" CANCELING = "canceling"
tests/test_run_tool.py +2 −2 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ def test_cancel_tool(nova_instance: Connection) -> None: test_tool.run_interactive(data_store=store, params=params, check_url=False) test_tool.cancel() state = test_tool.get_status() assert state == WorkState.STOPPING assert state == WorkState.CANCELING def test_cancel_tool_while_uploading(nova_instance: Connection, galaxy_instance: GalaxyInstance) -> None: Loading @@ -112,7 +112,7 @@ def test_cancel_tool_while_uploading(nova_instance: Connection, galaxy_instance: assert state == WorkState.UPLOADING_DATA test_tool.cancel() state = test_tool.get_status() assert state == WorkState.STOPPING assert state == WorkState.CANCELING test_tool.wait_for_results() state = test_tool.get_status() assert state == WorkState.CANCELED Loading