Permalink
Browse files

Another check on failed status and test

  • Loading branch information...
1 parent 88a3c60 commit dc3bba9362fab6a7fd5e76aa6e817017c3958668 @jsurloppe jsurloppe committed Dec 3, 2016
Showing with 22 additions and 1 deletion.
  1. +1 −1 rq/queue.py
  2. +21 −0 tests/test_queue.py
View
@@ -111,7 +111,7 @@ def fetch_job(self, job_id):
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):
View
@@ -505,6 +505,27 @@ def test_requeue_job(self):
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()

0 comments on commit dc3bba9

Please sign in to comment.