mirror of https://github.com/rq/rq.git
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>
This commit is contained in:
parent
46b5cf64c3
commit
5798cddd04
|
@ -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):
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue