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)