From 5798cddd0463cb2e639469689aaad26cc2bbc28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=B3=20Albert=20i=20Beltran?= Date: Wed, 15 Feb 2023 11:17:09 +0100 Subject: [PATCH] fix: queue.result_ttl=-1 (#1819) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: queue.result_ttl=-1 Signed-off-by: Simó Albert i Beltran * test: queue.result_ttl=0 Signed-off-by: Simó Albert i Beltran * fix: queue.result_ttl=-1 Signed-off-by: Simó Albert i Beltran --------- Signed-off-by: Simó Albert i Beltran --- rq/results.py | 5 ++++- tests/test_results.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/rq/results.py b/rq/results.py index a6dafde..8ff770d 100644 --- a/rq/results.py +++ b/rq/results.py @@ -169,7 +169,10 @@ class Result(object): if pipeline is None: self.id = result.decode() if ttl is not None: - connection.expire(key, ttl) + if ttl == -1: + connection.persist(key) + else: + connection.expire(key, ttl) return self.id def serialize(self): diff --git a/tests/test_results.py b/tests/test_results.py index 4f705f5..9bc1b9e 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -214,3 +214,25 @@ class TestScheduledJobRegistry(RQTestCase): job = queue.enqueue(div_by_zero) self.assertEqual(job.latest_result().type, Result.Type.FAILED) + + def test_job_return_value_result_ttl_infinity(self): + """Test job.return_value when queue.result_ttl=-1""" + queue = Queue(connection=self.connection, result_ttl=-1) + job = queue.enqueue(say_hello) + + # Returns None when there's no result + self.assertIsNone(job.return_value()) + + Result.create(job, Result.Type.SUCCESSFUL, ttl=-1, return_value=1) + self.assertEqual(job.return_value(), 1) + + def test_job_return_value_result_ttl_zero(self): + """Test job.return_value when queue.result_ttl=0""" + queue = Queue(connection=self.connection, result_ttl=0) + job = queue.enqueue(say_hello) + + # Returns None when there's no result + self.assertIsNone(job.return_value()) + + Result.create(job, Result.Type.SUCCESSFUL, ttl=0, return_value=1) + self.assertIsNone(job.return_value())