Commit f1c522c2 authored by Yakubov, Sergey's avatar Yakubov, Sergey
Browse files

refactor stop/cancel functions

parent a422158d
Loading
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -161,11 +161,9 @@ 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, stop: bool = False) -> bool:
        """Cancels or stops a job in Galaxy."""
    def stop(self) -> bool:
        """Stops a job in Galaxy."""
        self.url = None
        self.status.state = WorkState.CANCELING
        if stop:
        self.status.state = WorkState.STOPPING
        response = self.galaxy_instance.make_put_request(
            f"{self.store.nova_connection.galaxy_url}/api/jobs/{self.id}/finish"
@@ -175,9 +173,13 @@ class Job:
        else:
            self.status.error_msg = "could not stop job"
            return False

    def cancel(self) -> bool:
        """Cancel a job in Galaxy."""
        self.url = None
        self.status.state = WorkState.CANCELING
        try:
            success = self.galaxy_instance.jobs.cancel_job(self.id)
            return success
            return self.galaxy_instance.jobs.cancel_job(self.id)
        except Exception:
            return False

+2 −2
Original line number Diff line number Diff line
@@ -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(stop=True)
            self._job.stop()

    def cancel(self) -> None:
        """Cancels the tool execution and gets rid of any results collected."""
        if self._job:
            self._job.cancel(stop=False)
            self._job.cancel()

    def get_stdout(self, position: Optional[int] = None, length: Optional[int] = None) -> Optional[str]:
        """Get the current STDOUT for a tool.