Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show lock count when available and greater than zero #71

Merged
merged 3 commits into from
Sep 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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