From c68494904594e8794d3bae9e63f8c2fcd44102c3 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 21 Mar 2012 15:24:32 +0100 Subject: [PATCH] Don't expose the FailedQueue class at the top-level. This fixes #36. --- rq/__init__.py | 4 ++-- rq/queue.py | 5 +++++ tests/test_queue.py | 14 +++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/rq/__init__.py b/rq/__init__.py index 7256ee6..6451efb 100644 --- a/rq/__init__.py +++ b/rq/__init__.py @@ -1,6 +1,6 @@ from redis import Redis from .proxy import conn -from .queue import Queue, FailedQueue +from .queue import Queue, get_failed_queue from .job import cancel_job, requeue_job from .worker import Worker from .version import VERSION @@ -22,6 +22,6 @@ def use_redis(redis=None): __all__ = [ 'conn', 'use_redis', - 'Queue', 'FailedQueue', 'Worker', + 'Queue', 'get_failed_queue', 'Worker', 'cancel_job', 'requeue_job'] __version__ = VERSION diff --git a/rq/queue.py b/rq/queue.py index f783be7..5a9b914 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -5,6 +5,11 @@ from .job import Job from .exceptions import NoSuchJobError, UnpickleError, InvalidJobOperationError +def get_failed_queue(): + """Returns a handle to the special failed queue.""" + return FailedQueue() + + def compact(lst): return [item for item in lst if item is not None] diff --git a/tests/test_queue.py b/tests/test_queue.py index 1cf6b82..ea0e74e 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -1,6 +1,6 @@ from tests import RQTestCase from tests.fixtures import say_hello, div_by_zero -from rq import Queue, FailedQueue +from rq import Queue, get_failed_queue from rq.job import Job from rq.exceptions import InvalidJobOperationError @@ -199,14 +199,14 @@ class TestFailedQueue(RQTestCase): job = Job.create(div_by_zero, 1, 2, 3) job.origin = 'fake' job.save() - FailedQueue().quarantine(job, Exception('Some fake error')) + get_failed_queue().quarantine(job, Exception('Some fake error')) - self.assertItemsEqual(Queue.all(), [FailedQueue()]) - self.assertEquals(FailedQueue().count, 1) + self.assertItemsEqual(Queue.all(), [get_failed_queue()]) + self.assertEquals(get_failed_queue().count, 1) - FailedQueue().requeue(job.id) + get_failed_queue().requeue(job.id) - self.assertEquals(FailedQueue().count, 0) + self.assertEquals(get_failed_queue().count, 0) self.assertEquals(Queue('fake').count, 1) def test_requeue_nonfailed_job_fails(self): @@ -216,4 +216,4 @@ class TestFailedQueue(RQTestCase): # Assert that we cannot requeue a job that's not on the failed queue with self.assertRaises(InvalidJobOperationError): - FailedQueue().requeue(job.id) + get_failed_queue().requeue(job.id)