Repository: AgnostiqHQ/covalent
Pull request #1623 (2023-05-05 20:16:48)

remove duplicate _get_cancel_requested
<!--
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Increment the version number in the /VERSION file. If this is a bugfix, increment the patch version (the rightmost number), for example 0.18.2 becomes 0.18.3. If it's a new feature, increment the minor version (the middle number), for example 0.18.2 becomes 0.19.0.
⚠️ Add a note to /CHANGELOG.md with your version number and the date, summarizing the changes.
⚠️ If your pull request fixes an open issue, please link to the issue.
⚠️ Rebase the latest changes from the develop branch. Assuming origin points to https://github.com/AgnostiqHQ/covalent, you should run git rebase origin/develop.
-->

- [ ] I have added the tests to cover my changes.
- [x] I have updated the documentation and CHANGELOG accordingly.
- [x] I have read the CONTRIBUTING document.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/AgnostiqHQ/covalent/pull/1623?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) Report
> Merging [#1623](https://app.codecov.io/gh/AgnostiqHQ/covalent/pull/1623?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (bad74c6) into [develop](https://app.codecov.io/gh/AgnostiqHQ/covalent/commit/53e0cca0fdb1f576ddcffa681f2546d3aaa0877a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (53e0cca) will **increase** coverage by `1.43%`.
> The diff coverage is `100.00%`.

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://app.codecov.io/gh/AgnostiqHQ/covalent/pull/1623/graphs/tree.svg?width=650&height=150&src=pr&token=YGHCB3DE4P&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)](https://app.codecov.io/gh/AgnostiqHQ/covalent/pull/1623?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)

```diff
@@             Coverage Diff             @@
##           develop    #1623      +/-   ##
===========================================
+ Coverage    85.96%   87.40%   +1.43%     
===========================================
  Files          159       83      -76     
  Lines         6671     4978    -1693     
  Branches       145        0     -145     
===========================================
- Hits          5735     4351    -1384     
+ Misses         834      627     -207     
+ Partials       102        0     -102     
```

| Flag | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| Dispatcher | `87.50% <100.00%> (+0.19%)` | :arrow_up: | |
| Functional_Tests | `?` | | |
| SDK | `87.34% <ø> (ø)` | | Carriedforward from [53e0cca](https://app.codecov.io/gh/AgnostiqHQ/covalent/commit/53e0cca0fdb1f576ddcffa681f2546d3aaa0877a?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) |
| UI_Frontend | `?` | | |

*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) to find out more.

</details>
madhur-tandon: CC: @kessler-frost @santoshkumarradha @AlejandroEsquivel 
This should be ready as well.
madhur-tandon: @kessler-frost I have edited the changelog 😅 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eee9f235..d17558bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Removed
 
 - Duplicate mocks for `UI_SRVDIR`
+- Duplicate `_get_cancel_requested` method from `covalent_dispatcher/_core/runner.py`
 
 ### Authors
 
diff --git a/covalent_dispatcher/_core/runner.py b/covalent_dispatcher/_core/runner.py
index abf8c5bb..c87d5111 100644
--- a/covalent_dispatcher/_core/runner.py
+++ b/covalent_dispatcher/_core/runner.py
@@ -135,7 +135,7 @@ async def _run_abstract_task(
     timestamp = datetime.now(timezone.utc)
 
     try:
-        cancel_req = await _get_cancel_requested(dispatch_id, node_id)
+        cancel_req = await executor_proxy._get_cancel_requested(dispatch_id, node_id)
         if cancel_req:
             app_log.debug(f"Don't run cancelled task {dispatch_id}:{node_id}")
             return datasvc.generate_node_result(
@@ -418,18 +418,3 @@ def _get_metadata_for_nodes(dispatch_id: str, node_ids: list) -> List[Any]:
     res = datasvc.get_result_object(dispatch_id)
     tg = res.lattice.transport_graph
     return list(map(lambda x: tg.get_node_value(x, "metadata"), node_ids))
-
-
-async def _get_cancel_requested(dispatch_id: str, task_id: int) -> Any:
-    """
-    Query if a specific task has been requested to be cancelled
-
-    Arg(s)
-        dispatch_id: Dispatch ID of the workflow
-        task_id: ID of the node to be cancelled
-
-    Return(s)
-        Whether the task has been requested to be cancelled or not
-    """
-    records = await get_jobs_metadata(dispatch_id, [task_id])
-    return records[0]["cancel_requested"]


Test patch:
diff --git a/tests/covalent_dispatcher_tests/_core/runner_test.py b/tests/covalent_dispatcher_tests/_core/runner_test.py
index d37b7352..12103824 100644
--- a/tests/covalent_dispatcher_tests/_core/runner_test.py
+++ b/tests/covalent_dispatcher_tests/_core/runner_test.py
@@ -35,13 +35,13 @@ from covalent._workflow.lattice import Lattice
 from covalent_dispatcher._core.runner import (
     _cancel_task,
     _gather_deps,
-    _get_cancel_requested,
     _get_metadata_for_nodes,
     _run_abstract_task,
     _run_task,
     cancel_tasks,
     get_executor,
 )
+from covalent_dispatcher._core.runner_modules.executor_proxy import _get_cancel_requested
 from covalent_dispatcher._db.datastore import DataStore
 
 TEST_RESULTS_DIR = "/tmp/results"
@@ -166,7 +166,7 @@ async def test_run_abstract_task_get_cancel_requested(mocker):
         side_effect=RuntimeError(),
     )
     mock_get_cancel_requested = mocker.patch(
-        "covalent_dispatcher._core.runner._get_cancel_requested",
+        "covalent_dispatcher._core.runner_modules.executor_proxy._get_cancel_requested",
         return_value=AsyncMock(return_value=True),
     )
     mock_generate_node_result = mocker.patch(
@@ -347,7 +347,8 @@ async def test__get_cancel_requested(mocker):
     dispatch_id = "abcd"
     task_id = 0
     mock_get_jobs_metadata = mocker.patch(
-        "covalent_dispatcher._core.runner.get_jobs_metadata", return_value=AsyncMock()
+        "covalent_dispatcher._core.runner_modules.executor_proxy.job_manager.get_jobs_metadata",
+        return_value=AsyncMock(),
     )
 
     await _get_cancel_requested(dispatch_id, task_id)