Fixed #731 - Support for deleting Queues

main
Theo 7 years ago
parent 009c478822
commit 160fe99323

@ -111,6 +111,12 @@ class Queue(object):
script = self.connection.register_script(script) script = self.connection.register_script(script)
return script(keys=[self.key]) return script(keys=[self.key])
def delete(self):
"""Deletes the queue and all the associated messages on the queue."""
self.empty()
self.connection.srem(self.redis_queues_keys, self._key)
self.connection.delete(self._key)
def is_empty(self): def is_empty(self):
"""Returns whether the current queue is empty.""" """Returns whether the current queue is empty."""
return self.count == 0 return self.count == 0

@ -72,6 +72,20 @@ class TestQueue(RQTestCase):
self.testconn.rpush('rq:queue:example', 'sentinel message') self.testconn.rpush('rq:queue:example', 'sentinel message')
self.assertEqual(q.is_empty(), False) self.assertEqual(q.is_empty(), False)
def test_queue_delete(self):
"""Test queue.delete properly removes queue"""
q = Queue('example')
self.testconn.rpush('rq:queue:example', 'foo')
self.testconn.rpush('rq:queue:example', 'bar')
self.assertEqual(2, len(q.get_job_ids()))
q.delete()
self.assertEqual(0, len(q.get_job_ids()))
self.assertEqual(0, len(self.testconn.smembers(Queue.redis_queues_keys)))
self.assertEqual(False, self.testconn.exists(q.key))
def test_remove(self): def test_remove(self):
"""Ensure queue.remove properly removes Job from queue.""" """Ensure queue.remove properly removes Job from queue."""
q = Queue('example') q = Queue('example')

Loading…
Cancel
Save