Loading src/nova/galaxy/connection.py +29 −4 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class ConnectionHelper: """Manages datastore for current connection. Should not be instantiated manually. Use Connection.connect() instead. Any stores created using the connection will be automatically purged after connection is closed, unless Datastore.persist() is called for that store. be persisted after connection is closed, unless Datastore.mark_for_cleanup() is called for that store. """ def __init__(self, galaxy_instance: galaxy.GalaxyInstance, galaxy_url: str): Loading @@ -44,11 +44,30 @@ class ConnectionHelper: @deprecated(version="0.8.0", reason="Should use `get_data_store() instead.") def create_data_store(self, name: str) -> Datastore: """Creates a datastore with the given name.""" """DEPRECATED. Creates a datastore with the given name or returns an existing data store with that name. Parameters ---------- name: str Name of the data store. """ return self.get_data_store(name=name, create=True) def get_data_store(self, name: str, create: bool = True) -> Datastore: """Creates a datastore with the given name.""" """Fetches a datastore with the given name. Parameters ---------- name: str Name of the data store. create: bool If true, creates a data store if one does not exist with the specified name. Returns ------- Datastore Returns the specified or newly created data store. """ histories = self.galaxy_instance.histories.get_histories(name=name) if len(histories) > 0: store = Datastore(name, self, histories[0]["id"]) Loading @@ -63,7 +82,13 @@ class ConnectionHelper: raise Exception("Data store does not exist and auto creation is set to false.") def remove_data_store(self, store: Datastore) -> None: """Permanently deletes the data store with the given name.""" """Permanently deletes the data store with the given name. Parameters ---------- store: Datastore The data store to remove from this connection. """ store.cleanup() self.datastores.remove(store) Loading src/nova/galaxy/job.py +9 −4 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ class Job: self.galaxy_instance = self.store.nova_connection.galaxy_instance self.status = JobStatus() self.url: Optional[str] = None self.thread: Optional[Thread] = None def _run_and_wait(self, params: Optional[Parameters]) -> None: """Runs tools and waits for result.""" Loading @@ -53,10 +54,10 @@ class Job: def run(self, params: Optional[Parameters], wait: bool) -> Optional[Outputs]: """Runs a job in Galaxy.""" if self.status.state in [WorkState.NOT_STARTED, WorkState.FINISHED, WorkState.ERROR]: thread = Thread(target=self._run_and_wait, args=(params,)) thread.start() self.thread = Thread(target=self._run_and_wait, args=(params,)) self.thread.start() if wait: thread.join() self.join_job_thread() return self.get_results() return None else: Loading Loading @@ -127,7 +128,11 @@ class Job: self.status.state = WorkState.ERROR return self.galaxy_instance.jobs.cancel_job(self.id) def wait_for_results(self, timeout: int = 12000) -> None: def join_job_thread(self) -> None: if self.thread: self.thread.join() def wait_for_results(self, timeout: float = 12000) -> None: """Wait for job to finish.""" self.galaxy_instance.jobs.wait_for_job(self.id, maxwait=timeout) Loading src/nova/galaxy/tool.py +3 −9 Original line number Diff line number Diff line Loading @@ -130,16 +130,10 @@ class Tool(AbstractWork): return self._job.get_results() return None def wait_for_results(self, timeout: int = 12000) -> None: def wait_for_results(self) -> None: """Wait for this Tool to finish running.""" if self._job: timer = 0 max_tries = 100 while timer < max_tries: try: self._job.wait_for_results(timeout) return except Exception: timer += 1 self._job.join_job_thread() def stop(self) -> None: """Stop the tool, but keep any existing results.""" Loading tests/conftest.py +2 −2 Original line number Diff line number Diff line Loading @@ -13,11 +13,11 @@ GALAXY_API_KEY = os.environ.get("NOVA_GALAXY_TEST_GALAXY_KEY") @pytest.fixture def nova_instance() -> Connection: nova = Connection(GALAXY_URL, GALAXY_API_KEY) nova = Connection(GALAXY_URL, GALAXY_API_KEY) # type: ignore return nova @pytest.fixture def galaxy_instance() -> GalaxyInstance: galaxy = GalaxyInstance(url=GALAXY_URL, key=GALAXY_API_KEY) galaxy = GalaxyInstance(url=GALAXY_URL, key=GALAXY_API_KEY) # type: ignore return galaxy tests/test_data_store.py +4 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ def test_no_persist_store(nova_instance: Connection, galaxy_instance: GalaxyInst def test_persist_store(nova_instance: Connection, galaxy_instance: GalaxyInstance) -> None: with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") store.persist() history = galaxy_instance.histories.get_histories(name=store.name) assert len(history) > 0 Loading @@ -35,7 +35,7 @@ def test_persist_store(nova_instance: Connection, galaxy_instance: GalaxyInstanc def test_manual_cleanup_store(nova_instance: Connection, galaxy_instance: GalaxyInstance) -> None: with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") history = galaxy_instance.histories.get_histories(name=store.name) assert len(history) > 0 store.cleanup() Loading @@ -59,14 +59,14 @@ def test_manual_connection_close(nova_instance: Connection, galaxy_instance: Gal def test_recover_tools(nova_instance: Connection) -> None: first_id: Optional[str] = "" with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") store.persist() test_tool = Tool(TEST_INT_TOOL_ID) test_tool.run_interactive(data_store=store) first_id = test_tool.get_uid() with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") store.mark_for_cleanup() tools = store.recover_tools() assert len(tools) > 0 Loading Loading
src/nova/galaxy/connection.py +29 −4 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class ConnectionHelper: """Manages datastore for current connection. Should not be instantiated manually. Use Connection.connect() instead. Any stores created using the connection will be automatically purged after connection is closed, unless Datastore.persist() is called for that store. be persisted after connection is closed, unless Datastore.mark_for_cleanup() is called for that store. """ def __init__(self, galaxy_instance: galaxy.GalaxyInstance, galaxy_url: str): Loading @@ -44,11 +44,30 @@ class ConnectionHelper: @deprecated(version="0.8.0", reason="Should use `get_data_store() instead.") def create_data_store(self, name: str) -> Datastore: """Creates a datastore with the given name.""" """DEPRECATED. Creates a datastore with the given name or returns an existing data store with that name. Parameters ---------- name: str Name of the data store. """ return self.get_data_store(name=name, create=True) def get_data_store(self, name: str, create: bool = True) -> Datastore: """Creates a datastore with the given name.""" """Fetches a datastore with the given name. Parameters ---------- name: str Name of the data store. create: bool If true, creates a data store if one does not exist with the specified name. Returns ------- Datastore Returns the specified or newly created data store. """ histories = self.galaxy_instance.histories.get_histories(name=name) if len(histories) > 0: store = Datastore(name, self, histories[0]["id"]) Loading @@ -63,7 +82,13 @@ class ConnectionHelper: raise Exception("Data store does not exist and auto creation is set to false.") def remove_data_store(self, store: Datastore) -> None: """Permanently deletes the data store with the given name.""" """Permanently deletes the data store with the given name. Parameters ---------- store: Datastore The data store to remove from this connection. """ store.cleanup() self.datastores.remove(store) Loading
src/nova/galaxy/job.py +9 −4 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ class Job: self.galaxy_instance = self.store.nova_connection.galaxy_instance self.status = JobStatus() self.url: Optional[str] = None self.thread: Optional[Thread] = None def _run_and_wait(self, params: Optional[Parameters]) -> None: """Runs tools and waits for result.""" Loading @@ -53,10 +54,10 @@ class Job: def run(self, params: Optional[Parameters], wait: bool) -> Optional[Outputs]: """Runs a job in Galaxy.""" if self.status.state in [WorkState.NOT_STARTED, WorkState.FINISHED, WorkState.ERROR]: thread = Thread(target=self._run_and_wait, args=(params,)) thread.start() self.thread = Thread(target=self._run_and_wait, args=(params,)) self.thread.start() if wait: thread.join() self.join_job_thread() return self.get_results() return None else: Loading Loading @@ -127,7 +128,11 @@ class Job: self.status.state = WorkState.ERROR return self.galaxy_instance.jobs.cancel_job(self.id) def wait_for_results(self, timeout: int = 12000) -> None: def join_job_thread(self) -> None: if self.thread: self.thread.join() def wait_for_results(self, timeout: float = 12000) -> None: """Wait for job to finish.""" self.galaxy_instance.jobs.wait_for_job(self.id, maxwait=timeout) Loading
src/nova/galaxy/tool.py +3 −9 Original line number Diff line number Diff line Loading @@ -130,16 +130,10 @@ class Tool(AbstractWork): return self._job.get_results() return None def wait_for_results(self, timeout: int = 12000) -> None: def wait_for_results(self) -> None: """Wait for this Tool to finish running.""" if self._job: timer = 0 max_tries = 100 while timer < max_tries: try: self._job.wait_for_results(timeout) return except Exception: timer += 1 self._job.join_job_thread() def stop(self) -> None: """Stop the tool, but keep any existing results.""" Loading
tests/conftest.py +2 −2 Original line number Diff line number Diff line Loading @@ -13,11 +13,11 @@ GALAXY_API_KEY = os.environ.get("NOVA_GALAXY_TEST_GALAXY_KEY") @pytest.fixture def nova_instance() -> Connection: nova = Connection(GALAXY_URL, GALAXY_API_KEY) nova = Connection(GALAXY_URL, GALAXY_API_KEY) # type: ignore return nova @pytest.fixture def galaxy_instance() -> GalaxyInstance: galaxy = GalaxyInstance(url=GALAXY_URL, key=GALAXY_API_KEY) galaxy = GalaxyInstance(url=GALAXY_URL, key=GALAXY_API_KEY) # type: ignore return galaxy
tests/test_data_store.py +4 −4 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ def test_no_persist_store(nova_instance: Connection, galaxy_instance: GalaxyInst def test_persist_store(nova_instance: Connection, galaxy_instance: GalaxyInstance) -> None: with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") store.persist() history = galaxy_instance.histories.get_histories(name=store.name) assert len(history) > 0 Loading @@ -35,7 +35,7 @@ def test_persist_store(nova_instance: Connection, galaxy_instance: GalaxyInstanc def test_manual_cleanup_store(nova_instance: Connection, galaxy_instance: GalaxyInstance) -> None: with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") history = galaxy_instance.histories.get_histories(name=store.name) assert len(history) > 0 store.cleanup() Loading @@ -59,14 +59,14 @@ def test_manual_connection_close(nova_instance: Connection, galaxy_instance: Gal def test_recover_tools(nova_instance: Connection) -> None: first_id: Optional[str] = "" with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") store.persist() test_tool = Tool(TEST_INT_TOOL_ID) test_tool.run_interactive(data_store=store) first_id = test_tool.get_uid() with nova_instance.connect() as connection: store = connection.create_data_store(name="nova_galaxy_testing") store = connection.get_data_store(name="nova_galaxy_testing") store.mark_for_cleanup() tools = store.recover_tools() assert len(tools) > 0 Loading