diff --git a/rq/queue.py b/rq/queue.py index 9e0cf702..68d72c5a 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -448,7 +448,7 @@ nd job.perform() job.set_status(JobStatus.FINISHED) job.save(include_meta=False) - job.cleanup(DEFAULT_RESULT_TTL) + job.cleanup(job.get_result_ttl(default_ttl=DEFAULT_RESULT_TTL)) return job @classmethod diff --git a/tests/test_queue.py b/tests/test_queue.py index 510c6714..c03fd09c 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -335,6 +335,18 @@ class TestQueue(RQTestCase): job = queue.enqueue_job(job) self.assertEqual(job.timeout, 15) + def test_synchronous_timeout(self): + queue = Queue(is_async=False) + + no_expire_job = queue.enqueue(echo, result_ttl=-1) + self.assertEqual(queue.connection.ttl(no_expire_job.key), -1) + + delete_job = queue.enqueue(echo, result_ttl=0) + self.assertEqual(queue.connection.ttl(delete_job.key), -2) + + keep_job = queue.enqueue(echo, result_ttl=100) + self.assertLessEqual(queue.connection.ttl(keep_job.key), 100) + def test_enqueue_explicit_args(self): """enqueue() works for both implicit/explicit args.""" q = Queue()