Encapsulate the result property (it should not directly be set).

This commit is contained in:
Vincent Driessen 2012-02-13 16:43:27 +01:00
parent 6266f68310
commit 7bda1ca969
2 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -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):