From ee359120eeee8e0f5edbf4a0f0ae924ead424956 Mon Sep 17 00:00:00 2001 From: thiagogds Date: Thu, 24 Oct 2024 09:54:09 +0200 Subject: [PATCH] Use correct redis connection (#7077) --- redash/monitor.py | 2 +- tests/test_monitor.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/test_monitor.py diff --git a/redash/monitor.py b/redash/monitor.py index 77521975c5..4ba3f00956 100644 --- a/redash/monitor.py +++ b/redash/monitor.py @@ -59,7 +59,7 @@ def get_status(): def rq_job_ids(): - queues = Queue.all(connection=redis_connection) + queues = Queue.all(connection=rq_redis_connection) started_jobs = [StartedJobRegistry(queue=q).get_job_ids() for q in queues] queued_jobs = [q.job_ids for q in queues] diff --git a/tests/test_monitor.py b/tests/test_monitor.py new file mode 100644 index 0000000000..a5bbc3d446 --- /dev/null +++ b/tests/test_monitor.py @@ -0,0 +1,23 @@ +from unittest.mock import MagicMock, patch + +from redash import rq_redis_connection +from redash.monitor import rq_job_ids + + +def test_rq_job_ids_uses_rq_redis_connection(): + mock_queue = MagicMock() + mock_queue.job_ids = [] + + mock_registry = MagicMock() + mock_registry.get_job_ids.return_value = [] + + with patch("redash.monitor.Queue") as mock_Queue, patch( + "redash.monitor.StartedJobRegistry" + ) as mock_StartedJobRegistry: + mock_Queue.all.return_value = [mock_queue] + mock_StartedJobRegistry.return_value = mock_registry + + rq_job_ids() + + mock_Queue.all.assert_called_once_with(connection=rq_redis_connection) + mock_StartedJobRegistry.assert_called_once_with(queue=mock_queue)