fix: queue.result_ttl=-1 (#1819)

* test: queue.result_ttl=-1

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>

* test: queue.result_ttl=0

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>

* fix: queue.result_ttl=-1

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>

---------

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>
main
Simó Albert i Beltran 2 years ago committed by GitHub
parent 46b5cf64c3
commit 5798cddd04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -169,6 +169,9 @@ class Result(object):
if pipeline is None: if pipeline is None:
self.id = result.decode() self.id = result.decode()
if ttl is not None: if ttl is not None:
if ttl == -1:
connection.persist(key)
else:
connection.expire(key, ttl) connection.expire(key, ttl)
return self.id return self.id

@ -214,3 +214,25 @@ class TestScheduledJobRegistry(RQTestCase):
job = queue.enqueue(div_by_zero) job = queue.enqueue(div_by_zero)
self.assertEqual(job.latest_result().type, Result.Type.FAILED) 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())

Loading…
Cancel
Save