From 93a8f711572adfe9c8c06fc850d8d47c95b46a5b Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Sat, 19 Sep 2015 15:42:35 +0200 Subject: [PATCH 1/3] Only show lock count when available and greater than zero --- django_q/brokers/__init__.py | 5 +++++ django_q/monitor.py | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/django_q/brokers/__init__.py b/django_q/brokers/__init__.py index a8380ee5..0d10cacc 100644 --- a/django_q/brokers/__init__.py +++ b/django_q/brokers/__init__.py @@ -29,6 +29,11 @@ def queue_size(self): """ pass + def lock_size(self): + """ + :return: the number of tasks currently awaiting acknowledgement + """ + def delete_queue(self): """ Deletes the queue from the broker diff --git a/django_q/monitor.py b/django_q/monitor.py index 3671e83a..6a3bcf4a 100644 --- a/django_q/monitor.py +++ b/django_q/monitor.py @@ -83,8 +83,9 @@ def monitor(run_once=False, broker=None): # bottom bar i += 1 queue_size = broker.queue_size() - if hasattr(broker, 'lock_size'): - queue_size = '{}({})'.format(queue_size, broker.lock_size()) + lock_size = broker.lock_size() + if lock_size: + queue_size = '{}({})'.format(queue_size, lock_size) print(term.move(i, 0) + term.white_on_cyan(term.center(broker.info(), width=col_width * 2))) print(term.move(i, 2 * col_width) + term.black_on_cyan(term.center(_('Queued'), width=col_width))) print(term.move(i, 3 * col_width) + term.white_on_cyan(term.center(queue_size, width=col_width))) From 7532cac93aea9fea2db002f8ce01351f830af943 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Sat, 19 Sep 2015 15:52:28 +0200 Subject: [PATCH 2/3] test for lock_size in main class --- django_q/tests/test_brokers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django_q/tests/test_brokers.py b/django_q/tests/test_brokers.py index 150adfdb..59514ccf 100644 --- a/django_q/tests/test_brokers.py +++ b/django_q/tests/test_brokers.py @@ -12,6 +12,7 @@ def test_broker(): broker.enqueue('test') broker.dequeue() broker.queue_size() + broker.lock_size() broker.purge_queue() broker.delete('id') broker.delete_queue() From dc47ebef3ca106c279cd60dfe0748febe343e1a0 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Sat, 19 Sep 2015 17:25:02 +0200 Subject: [PATCH 3/3] test for lock size in monitor --- django_q/tests/test_monitor.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/django_q/tests/test_monitor.py b/django_q/tests/test_monitor.py index 69d9af5e..2c73723b 100644 --- a/django_q/tests/test_monitor.py +++ b/django_q/tests/test_monitor.py @@ -1,6 +1,6 @@ import pytest -from django_q import async +from django_q import async, get_broker from django_q.cluster import Cluster from django_q.monitor import monitor, info from django_q.status import Stat @@ -23,9 +23,14 @@ def test_monitor(): assert stat.empty_queues() is True break assert found_c is True - # test lock size for orm broker + # test lock size Conf.ORM = 'default' - monitor(run_once=True) + b = get_broker('monitor_test') + b.enqueue('test') + b.dequeue() + assert b.lock_size() == 1 + monitor(run_once=True, broker=b) + b.delete_queue() Conf.ORM = None