Fix rq info not found workers information error, Fixes #1139 (#1149)

* Fix rq info not found workers information error, Fixes #1139

* Add test(#1149)
main
Yongtao Zhang 5 years ago committed by Selwin Ong
parent 75644ba948
commit 5bb03b9c2c

@ -118,9 +118,13 @@ def show_queues(queues, raw, by_queue, queue_class, worker_class):
def show_workers(queues, raw, by_queue, queue_class, worker_class): def show_workers(queues, raw, by_queue, queue_class, worker_class):
workers = set() workers = set()
if queues:
for queue in queues: for queue in queues:
for worker in worker_class.all(queue=queue): for worker in worker_class.all(queue=queue):
workers.add(worker) workers.add(worker)
else:
for worker in worker_class.all():
workers.add(worker)
if not by_queue: if not by_queue:

@ -189,6 +189,13 @@ class TestRQCli(RQTestCase):
self.assert_normal_execution(result) self.assert_normal_execution(result)
self.assertIn('0 workers, 0 queue', result.output) 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 = Queue(connection=self.connection)
queue.enqueue(say_hello) queue.enqueue(say_hello)
result = runner.invoke(main, ['info', '-u', self.redis_url, '--only-workers']) 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 = Queue(name='bar', connection=self.connection)
bar_queue.enqueue(say_hello) bar_queue.enqueue(say_hello)
worker = Worker([foo_queue, bar_queue], connection=self.connection) worker_1 = Worker([foo_queue, bar_queue], connection=self.connection)
worker.register_birth() worker_1.register_birth()
worker_2 = Worker([foo_queue, bar_queue], connection=self.connection) worker_2 = Worker([foo_queue, bar_queue], connection=self.connection)
worker_2.register_birth() worker_2.register_birth()

Loading…
Cancel
Save