From 3d4d6a86d5f73ccdedbb4d2ee596f957337a5fd3 Mon Sep 17 00:00:00 2001 From: glaslos Date: Fri, 27 Feb 2015 16:07:44 +0100 Subject: [PATCH] persist the job right before execution --- rq/job.py | 2 ++ tests/test_job.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rq/job.py b/rq/job.py index 5dbbcf5..7195ddb 100644 --- a/rq/job.py +++ b/rq/job.py @@ -485,6 +485,8 @@ class Job(object): # Job execution def perform(self): # noqa """Invokes the job function with the job arguments.""" + self.connection.persist(self.key) + self.ttl = self.connection.ttl(self.key) _job_stack.push(self.id) try: self._result = self.func(*self.args, **self.kwargs) diff --git a/tests/test_job.py b/tests/test_job.py index d715298..2e91751 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -345,14 +345,16 @@ class TestJob(RQTestCase): job = queue.enqueue(say_hello, ttl=ttl) self.assertEqual(job.get_ttl(), ttl) - def test_expire_during_execution(self): + def test_never_expire_during_execution(self): """Test what happens when job expires during execution""" - ttl = 2 + ttl = 1 queue = Queue(connection=self.testconn) - job = queue.enqueue(long_running_job, args=(4,), ttl=ttl) + job = queue.enqueue(long_running_job, args=(2,), ttl=ttl) self.assertEqual(job.get_ttl(), ttl) + job.save() job.perform() - self.assertFalse(job.exists(job.id)) + self.assertEqual(job.get_ttl(), -1) + self.assertTrue(job.exists(job.id)) self.assertEqual(job.result, 'Done sleeping...') def test_cleanup(self):