From 145884fcd5a016ee353da9ce1a586044bf058f45 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 24 Jul 2022 10:56:35 +0700 Subject: [PATCH] When stopped jobs are deleted, they should also be removed from FailedJobRegistry. (#1677) --- rq/job.py | 2 +- tests/test_job.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rq/job.py b/rq/job.py index fde9c0c..5ac40dd 100644 --- a/rq/job.py +++ b/rq/job.py @@ -772,7 +772,7 @@ class Job: serializer=self.serializer) registry.remove(self, pipeline=pipeline) - elif self.is_failed: + elif self.is_failed or self.is_stopped: self.failed_job_registry.remove(self, pipeline=pipeline) elif self.is_canceled: diff --git a/tests/test_job.py b/tests/test_job.py index df17f30..bf7af5b 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -621,6 +621,15 @@ class TestJob(RQTestCase): job.delete() self.assertFalse(job in registry) + job = Job.create(func=fixtures.say_hello, status=JobStatus.STOPPED, + connection=self.testconn, origin='default', serializer=JSONSerializer) + job.save() + registry = FailedJobRegistry(connection=self.testconn, serializer=JSONSerializer) + registry.add(job, 500) + + job.delete() + self.assertFalse(job in registry) + job = Job.create(func=fixtures.say_hello, status=JobStatus.FINISHED, connection=self.testconn, origin='default', serializer=JSONSerializer) job.save()