diff options
author | BonfaceKilz | 2021-02-24 18:17:06 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-03-08 21:09:58 +0300 |
commit | d266756d26e78e77b99515802de51ec1151a7abb (patch) | |
tree | 50446df697585eae267741b475aee314cceca6e4 | |
parent | fde7e47975bcdc936b95f527a4880409ff54cf3e (diff) | |
download | genenetwork3-d266756d26e78e77b99515802de51ec1151a7abb.tar.gz |
Make the name of the redis job queue configurable
-rw-r--r-- | gn3/api/gemma.py | 1 | ||||
-rw-r--r-- | gn3/commands.py | 5 | ||||
-rw-r--r-- | gn3/settings.py | 3 | ||||
-rw-r--r-- | tests/integration/test_gemma.py | 1 | ||||
-rw-r--r-- | tests/unit/test_commands.py | 5 |
5 files changed, 11 insertions, 4 deletions
diff --git a/gn3/api/gemma.py b/gn3/api/gemma.py index c145eb4..bdba26e 100644 --- a/gn3/api/gemma.py +++ b/gn3/api/gemma.py @@ -68,6 +68,7 @@ file output is returned. return jsonify( unique_id=queue_cmd(conn=redis.Redis(), email=data.get("email"), + job_queue=app_defaults.get("REDIS_JOB_QUEUE"), cmd=f"{k_computation_cmd} && {gwa_cmd}"), status="queued", output_file=(f"{data.get('dataset_name')}_GWA_" diff --git a/gn3/commands.py b/gn3/commands.py index 51c1582..70ef2cf 100644 --- a/gn3/commands.py +++ b/gn3/commands.py @@ -33,7 +33,8 @@ def compose_gemma_cmd( return cmd -def queue_cmd(conn: Redis, cmd: str, email: Optional[str] = None) -> str: +def queue_cmd(conn: Redis, job_queue: str, + cmd: str, email: Optional[str] = None) -> str: """Given a command CMD; (optional) EMAIL; and a redis connection CONN, queue it in Redis with an initial status of 'queued'. The following status codes are supported: @@ -53,7 +54,7 @@ are supported: "result": "", "status": "queued"}.items(): conn.hset(key, value, unique_id) - conn.rpush("GN2::job-queue", + conn.rpush(job_queue, unique_id) if email: conn.hset("email", diff --git a/gn3/settings.py b/gn3/settings.py index 6a67c0a..ddff766 100644 --- a/gn3/settings.py +++ b/gn3/settings.py @@ -8,5 +8,6 @@ APP_DEFAULTS = { "GEMMA_WRAPPER_CMD": os.environ.get("GEMMA_WRAPPER", "gemma-wrapper"), "TMPDIR": os.environ.get("TMPDIR", tempfile.gettempdir()), "GENODIR": "", - "REDIS_URI": "redis://localhost:6379/0" + "REDIS_URI": "redis://localhost:6379/0", + "REDIS_JOB_QUEUE": "GN3::job-queue" } diff --git a/tests/integration/test_gemma.py b/tests/integration/test_gemma.py index 7f84b50..ed05cac 100644 --- a/tests/integration/test_gemma.py +++ b/tests/integration/test_gemma.py @@ -60,6 +60,7 @@ class GemmaAPITest(unittest.TestCase): mock_queue_cmd.assert_has_calls( [mock.call(conn=_redis_conn, email="me@me.com", + job_queue="GN3::job-queue", cmd=("gemma-wrapper --json -- -g " "genofile.txt -p test.txt " "-a genofile_snps.txt -gk > " diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py index d96706c..846d20c 100644 --- a/tests/unit/test_commands.py +++ b/tests/unit/test_commands.py @@ -41,6 +41,7 @@ class TestCommands(unittest.TestCase): self.assertRaises(RedisConnectionError, queue_cmd, cmd="ls", + job_queue="GN2::job-queue", conn=MockRedis(ping=lambda: False, hset=mock.MagicMock(), rpush=mock.MagicMock())) @@ -59,7 +60,8 @@ class TestCommands(unittest.TestCase): rpush=mock.MagicMock()) actual_unique_id = "cmd::2021-02-1217-3224-3224-1234" self.assertEqual(queue_cmd(cmd="ls", - conn=mock_redis_conn), + conn=mock_redis_conn, + job_queue="GN2::job-queue"), actual_unique_id) mock_redis_conn.hset.assert_has_calls( [mock.call("cmd", "ls", actual_unique_id), @@ -84,6 +86,7 @@ class TestCommands(unittest.TestCase): actual_unique_id = "cmd::2021-02-1217-3224-3224-1234" self.assertEqual(queue_cmd(cmd="ls", conn=mock_redis_conn, + job_queue="GN2::job-queue", email="me@me.com"), actual_unique_id) mock_redis_conn.hset.assert_has_calls( |