diff --git a/rq/cli/helpers.py b/rq/cli/helpers.py index 851f319..d27fbb0 100644 --- a/rq/cli/helpers.py +++ b/rq/cli/helpers.py @@ -118,8 +118,12 @@ def show_queues(queues, raw, by_queue, queue_class, worker_class): def show_workers(queues, raw, by_queue, queue_class, worker_class): workers = set() - for queue in queues: - for worker in worker_class.all(queue=queue): + if queues: + for queue in queues: + for worker in worker_class.all(queue=queue): + workers.add(worker) + else: + for worker in worker_class.all(): workers.add(worker) if not by_queue: diff --git a/tests/test_cli.py b/tests/test_cli.py index cf4df3b..343e286 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -189,6 +189,13 @@ class TestRQCli(RQTestCase): self.assert_normal_execution(result) self.assertIn('0 workers, 0 queue', result.output) + worker = Worker(['default'], connection=self.connection) + worker.register_birth() + result = runner.invoke(main, ['info', '-u', self.redis_url, '--only-workers']) + self.assert_normal_execution(result) + self.assertIn('1 workers, 0 queues', result.output) + worker.register_death() + queue = Queue(connection=self.connection) queue.enqueue(say_hello) result = runner.invoke(main, ['info', '-u', self.redis_url, '--only-workers']) @@ -201,8 +208,8 @@ class TestRQCli(RQTestCase): bar_queue = Queue(name='bar', connection=self.connection) bar_queue.enqueue(say_hello) - worker = Worker([foo_queue, bar_queue], connection=self.connection) - worker.register_birth() + worker_1 = Worker([foo_queue, bar_queue], connection=self.connection) + worker_1.register_birth() worker_2 = Worker([foo_queue, bar_queue], connection=self.connection) worker_2.register_birth()