mirror of https://github.com/rq/rq.git
Allow queues to be emptied.
This commit is contained in:
parent
9e33e1a08f
commit
e4055ca42f
|
@ -42,6 +42,10 @@ class Queue(object):
|
|||
"""Returns the Redis key for this Queue."""
|
||||
return self._key
|
||||
|
||||
def empty(self):
|
||||
"""Removes all messages on the queue."""
|
||||
conn.delete(self.key)
|
||||
|
||||
def is_empty(self):
|
||||
"""Returns whether the current queue is empty."""
|
||||
return self.count == 0
|
||||
|
|
|
@ -28,7 +28,20 @@ class TestQueue(RQTestCase):
|
|||
self.assertNotEquals(q2, q3)
|
||||
|
||||
|
||||
def test_queue_empty(self):
|
||||
def test_empty_queue(self):
|
||||
"""Emptying queues."""
|
||||
q = Queue('example')
|
||||
|
||||
self.testconn.rpush('rq:queue:example', 'foo')
|
||||
self.testconn.rpush('rq:queue:example', 'bar')
|
||||
self.assertEquals(q.is_empty(), False)
|
||||
|
||||
q.empty()
|
||||
|
||||
self.assertEquals(q.is_empty(), True)
|
||||
self.assertIsNone(self.testconn.lpop('rq:queue:example'))
|
||||
|
||||
def test_queue_is_empty(self):
|
||||
"""Detecting empty queues."""
|
||||
q = Queue('example')
|
||||
self.assertEquals(q.is_empty(), True)
|
||||
|
|
Loading…
Reference in New Issue