From 88a3c601772e84c0618c41a6815e33163f16f7bf Mon Sep 17 00:00:00 2001 From: Julien Surloppe Date: Sat, 3 Dec 2016 16:28:48 +0100 Subject: [PATCH 1/2] Fix get job on failed queue --- rq/queue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rq/queue.py b/rq/queue.py index 8231b08..d010855 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -111,7 +111,7 @@ class Queue(object): except NoSuchJobError: self.remove(job_id) else: - if job.origin == self.name: + if self == get_failed_queue(connection=self.connection) or job.origin == self.name: return job def get_job_ids(self, offset=0, length=-1): From dc3bba9362fab6a7fd5e76aa6e817017c3958668 Mon Sep 17 00:00:00 2001 From: Julien Surloppe Date: Sat, 3 Dec 2016 22:32:12 +0100 Subject: [PATCH 2/2] Another check on failed status and test --- rq/queue.py | 2 +- tests/test_queue.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rq/queue.py b/rq/queue.py index d010855..edd9380 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -111,7 +111,7 @@ class Queue(object): except NoSuchJobError: self.remove(job_id) else: - if self == get_failed_queue(connection=self.connection) or job.origin == self.name: + if job.origin == self.name or (job.is_failed and self == get_failed_queue(connection=self.connection)): return job def get_job_ids(self, offset=0, length=-1): diff --git a/tests/test_queue.py b/tests/test_queue.py index 015590a..75f59df 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -505,6 +505,27 @@ class TestFailedQueue(RQTestCase): self.assertEqual(get_failed_queue().count, 0) self.assertEqual(Queue('fake').count, 1) + def test_get_job_on_failed_queue(self): + default_queue = Queue() + failed_queue = get_failed_queue() + + job = default_queue.enqueue(div_by_zero, args=(1, 2, 3)) + + job_on_default_queue = default_queue.fetch_job(job.id) + job_on_failed_queue = failed_queue.fetch_job(job.id) + + self.assertIsNotNone(job_on_default_queue) + self.assertIsNone(job_on_failed_queue) + + job.set_status(JobStatus.FAILED) + + job_on_default_queue = default_queue.fetch_job(job.id) + job_on_failed_queue = failed_queue.fetch_job(job.id) + + self.assertIsNotNone(job_on_default_queue) + self.assertIsNotNone(job_on_failed_queue) + self.assertTrue(job_on_default_queue.is_failed) + def test_requeue_nonfailed_job_fails(self): """Requeueing non-failed jobs raises error.""" q = Queue()