From 01d71c898495e28fa380803a4328fe5106edbc02 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Thu, 10 Sep 2020 08:15:15 +0700 Subject: [PATCH] Fixes an issue where retried jobs should not be put in FailedJobRegistry (#1336) --- rq/worker.py | 2 +- tests/test_worker.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rq/worker.py b/rq/worker.py index f4de170..a4e3b25 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -856,7 +856,7 @@ class Worker(object): started_job_registry.remove(job, pipeline=pipeline) - if not self.disable_default_exception_handler: + if not self.disable_default_exception_handler and not retry: failed_job_registry = FailedJobRegistry(job.origin, job.connection, job_class=self.job_class) failed_job_registry.add(job, ttl=job.failure_ttl, diff --git a/tests/test_worker.py b/tests/test_worker.py index a5d4026..4ea8a30 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -379,16 +379,19 @@ class TestWorker(RQTestCase): queue = Queue(connection=connection) retry = Retry(max=2) job = queue.enqueue(div_by_zero, retry=retry) + registry = FailedJobRegistry(queue=queue) worker = Worker([queue]) # If job if configured to retry, it will be put back in the queue + # and not put in the FailedJobRegistry. # This is the original execution queue.empty() worker.handle_job_failure(job, queue) job.refresh() self.assertEqual(job.retries_left, 1) self.assertEqual([job.id], queue.job_ids) + self.assertFalse(job in registry) # First retry queue.empty() @@ -403,6 +406,8 @@ class TestWorker(RQTestCase): job.refresh() self.assertEqual(job.retries_left, 0) self.assertEqual([], queue.job_ids) + # If a job is no longer retries, it's put in FailedJobRegistry + self.assertTrue(job in registry) def test_retry_interval(self): """Retries with intervals are scheduled"""