Skip to content

Commit

Permalink
Merge pull request #71 from Koed00/dev
Browse files Browse the repository at this point in the history
Only show lock count when available and greater than zero
  • Loading branch information
Koed00 committed Sep 19, 2015
2 parents 000415a + dc47ebe commit 5e80675
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions django_q/brokers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions django_q/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
1 change: 1 addition & 0 deletions django_q/tests/test_brokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions django_q/tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand Down

0 comments on commit 5e80675

Please sign in to comment.