From 7bda1ca969700baa5dc94c22758a8e61d93b6ab9 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Mon, 13 Feb 2012 16:43:27 +0100 Subject: [PATCH] Encapsulate the result property (it should not directly be set). --- rq/job.py | 14 +++++++------- tests/test_job.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rq/job.py b/rq/job.py index 6b52645..5238967 100644 --- a/rq/job.py +++ b/rq/job.py @@ -68,7 +68,7 @@ class Job(object): self.origin = None self.enqueued_at = None self.ended_at = None - self.result = None + self._result = None self.exc_info = None @@ -116,12 +116,12 @@ class Job(object): written back to Redis will expire after a given amount of time (500 seconds by default). """ - if self._cached_result is None: + if self._result is None: rv = conn.hget(self.key, 'result') if rv is not None: # cache the result - self._cached_result = loads(rv) - return self._cached_result + self._result = loads(rv) + return self._result # Persistence @@ -152,7 +152,7 @@ class Job(object): self.description = description self.enqueued_at = to_date(enqueued_at) self.ended_at = to_date(ended_at) - self.result = result + self._result = result self.exc_info = exc_info def save(self): @@ -172,8 +172,8 @@ class Job(object): obj['enqueued_at'] = times.format(self.enqueued_at, 'UTC') if self.ended_at is not None: obj['ended_at'] = times.format(self.ended_at, 'UTC') - if self.result is not None: - obj['result'] = self.result + if self._result is not None: + obj['result'] = self._result if self.exc_info is not None: obj['exc_info'] = self.exc_info diff --git a/tests/test_job.py b/tests/test_job.py index 55e589e..6174d5b 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -27,7 +27,7 @@ class TestJob(RQTestCase): self.assertIsNone(job.origin, None) self.assertIsNone(job.enqueued_at, None) self.assertIsNone(job.ended_at, None) - self.assertIsNone(job.result, None) + self.assertIsNone(job.return_value, None) self.assertIsNone(job.exc_info, None) def test_create_typical_job(self): @@ -47,7 +47,7 @@ class TestJob(RQTestCase): # ...but metadata is not self.assertIsNone(job.origin) self.assertIsNone(job.enqueued_at) - self.assertIsNone(job.result) + self.assertIsNone(job.return_value) def test_save(self):