about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBonfaceKilz2021-02-24 22:38:22 +0300
committerBonfaceKilz2021-03-08 21:09:58 +0300
commit37b1a5da433d1976ff81a566c0fd022127f9fdb7 (patch)
treeed591de4b743ec6680034e98f783d05ba523b7d3
parentd266756d26e78e77b99515802de51ec1151a7abb (diff)
downloadgenenetwork3-37b1a5da433d1976ff81a566c0fd022127f9fdb7.tar.gz
Add extra endpoint for checking the status of a command
-rw-r--r--gn3/api/gemma.py14
-rw-r--r--tests/integration/test_gemma.py21
2 files changed, 33 insertions, 2 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py
index bdba26e..effae8a 100644
--- a/gn3/api/gemma.py
+++ b/gn3/api/gemma.py
@@ -73,3 +73,17 @@ file output is returned.
         status="queued",
         output_file=(f"{data.get('dataset_name')}_GWA_"
                      f"{__hash}.txt"))
+
+
+@gemma.route("/status/<unique_id>", methods=["GET"])
+def check_cmd_status(unique_id):
+    """Given a (url-encoded) UNIQUE-ID which is returned when hitting any of the
+gemma endpoints, return the status of the command
+
+    """
+    status = redis.Redis().hget(name=unique_id,
+                                key="status")
+    if not status:
+        return jsonify(status=128,
+                       error="The unique id you used does not exist!"), 500
+    return jsonify(status=status.decode("utf-8"))
diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py
index ed05cac..598c91f 100644
--- a/tests/integration/test_gemma.py
+++ b/tests/integration/test_gemma.py
@@ -9,8 +9,9 @@ from gn3.app import create_app
 
 @dataclass
 class MockRedis:
-    """Mock File object returned by request.files"""
+    """Mock the Redis Module"""
     redis: Callable
+    hget: Callable
 
 
 class GemmaAPITest(unittest.TestCase):
@@ -33,7 +34,7 @@ class GemmaAPITest(unittest.TestCase):
     def test_run_gemma(self, mock_gemma_computation_cmd,
                        mock_queue_cmd, mock_redis):
         """Test that gemma composes the command correctly"""
-        _redis_conn = MockRedis(redis=mock.MagicMock())
+        _redis_conn = MockRedis(redis=mock.MagicMock(), hget=mock.MagicMock())
         mock_redis.return_value = _redis_conn
         mock_gemma_computation_cmd.side_effect = [
             ("gemma-wrapper --json -- "
@@ -78,3 +79,19 @@ class GemmaAPITest(unittest.TestCase):
             {"unique_id": 'my-unique-id',
              "status": "queued",
              "output_file": "BXD_GWA_9lo8zwOOXbfB73EcyXxAYQ.txt"})
+
+    @mock.patch("gn3.api.gemma.redis.Redis")
+    def test_check_cmd_status(self, mock_redis):
+        """Test that you can check the status of a given command"""
+        mock_hget = mock.MagicMock()
+        mock_hget.return_value = b"test"
+        _redis_conn = MockRedis(redis=mock.MagicMock(), hget=mock_hget)
+        mock_redis.return_value = _redis_conn
+        response = self.app.get(("/gemma/status/"
+                                 "cmd%3A%3A2021-02-1217-3224-3224-1234"),
+                                follow_redirects=True)
+        mock_hget.assert_called_once_with(
+            name="cmd::2021-02-1217-3224-3224-1234",
+            key="status")
+        self.assertEqual(response.get_json(),
+                         {"status": "test"})