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

main
Vincent Driessen 13 years ago
parent 6266f68310
commit 7bda1ca969

@ -68,7 +68,7 @@ class Job(object):
self.origin = None self.origin = None
self.enqueued_at = None self.enqueued_at = None
self.ended_at = None self.ended_at = None
self.result = None self._result = None
self.exc_info = 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 written back to Redis will expire after a given amount of time (500
seconds by default). seconds by default).
""" """
if self._cached_result is None: if self._result is None:
rv = conn.hget(self.key, 'result') rv = conn.hget(self.key, 'result')
if rv is not None: if rv is not None:
# cache the result # cache the result
self._cached_result = loads(rv) self._result = loads(rv)
return self._cached_result return self._result
# Persistence # Persistence
@ -152,7 +152,7 @@ class Job(object):
self.description = description self.description = description
self.enqueued_at = to_date(enqueued_at) self.enqueued_at = to_date(enqueued_at)
self.ended_at = to_date(ended_at) self.ended_at = to_date(ended_at)
self.result = result self._result = result
self.exc_info = exc_info self.exc_info = exc_info
def save(self): def save(self):
@ -172,8 +172,8 @@ class Job(object):
obj['enqueued_at'] = times.format(self.enqueued_at, 'UTC') obj['enqueued_at'] = times.format(self.enqueued_at, 'UTC')
if self.ended_at is not None: if self.ended_at is not None:
obj['ended_at'] = times.format(self.ended_at, 'UTC') obj['ended_at'] = times.format(self.ended_at, 'UTC')
if self.result is not None: if self._result is not None:
obj['result'] = self.result obj['result'] = self._result
if self.exc_info is not None: if self.exc_info is not None:
obj['exc_info'] = self.exc_info obj['exc_info'] = self.exc_info

@ -27,7 +27,7 @@ class TestJob(RQTestCase):
self.assertIsNone(job.origin, None) self.assertIsNone(job.origin, None)
self.assertIsNone(job.enqueued_at, None) self.assertIsNone(job.enqueued_at, None)
self.assertIsNone(job.ended_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) self.assertIsNone(job.exc_info, None)
def test_create_typical_job(self): def test_create_typical_job(self):
@ -47,7 +47,7 @@ class TestJob(RQTestCase):
# ...but metadata is not # ...but metadata is not
self.assertIsNone(job.origin) self.assertIsNone(job.origin)
self.assertIsNone(job.enqueued_at) self.assertIsNone(job.enqueued_at)
self.assertIsNone(job.result) self.assertIsNone(job.return_value)
def test_save(self): def test_save(self):

Loading…
Cancel
Save