diff --git a/rq/queue.py b/rq/queue.py index 8231b08..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 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()