From 83369f3b9b60ec64639364b90ef2e0f41e7afdf9 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Thu, 23 Aug 2012 09:26:52 +0200 Subject: [PATCH] Prefer `result` over `return_value`. `return_value` still is available as a backward-compatible accessor. This fixes #116. --- rq/job.py | 5 ++++- tests/test_job.py | 4 ++-- tests/test_worker.py | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rq/job.py b/rq/job.py index b229e2f..0400f26 100644 --- a/rq/job.py +++ b/rq/job.py @@ -172,7 +172,7 @@ class Job(object): return (self.func_name, self.instance, self.args, self.kwargs) @property - def return_value(self): + def result(self): """Returns the return value of the job. Initially, right after enqueueing a job, the return value will be @@ -195,6 +195,9 @@ class Job(object): self._result = loads(rv) return self._result + """Backwards-compatibility accessor property `return_value`.""" + return_value = self.result + # Persistence def refresh(self): # noqa diff --git a/tests/test_job.py b/tests/test_job.py index 916e94c..5c914b9 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -25,7 +25,7 @@ class TestJob(RQTestCase): self.assertIsNone(job.origin) self.assertIsNone(job.enqueued_at) self.assertIsNone(job.ended_at) - self.assertIsNone(job.return_value) + self.assertIsNone(job.result) self.assertIsNone(job.exc_info) def test_create_typical_job(self): @@ -46,7 +46,7 @@ class TestJob(RQTestCase): # ...but metadata is not self.assertIsNone(job.origin) self.assertIsNone(job.enqueued_at) - self.assertIsNone(job.return_value) + self.assertIsNone(job.result) def test_create_instance_method_job(self): """Creation of jobs for instance methods.""" diff --git a/tests/test_worker.py b/tests/test_worker.py index a4f47e6..5e46a13 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -29,10 +29,10 @@ class TestWorker(RQTestCase): """Worker processes work fed via string arguments.""" q = Queue('foo') w = Worker([q]) - result = q.enqueue('tests.fixtures.say_hello', name='Frank') + job = q.enqueue('tests.fixtures.say_hello', name='Frank') self.assertEquals(w.work(burst=True), True, 'Expected at least some work done.') - self.assertEquals(result.return_value, 'Hi there, Frank!') + self.assertEquals(job.result, 'Hi there, Frank!') def test_work_is_unreadable(self): """Unreadable jobs are put on the failed queue.""" @@ -109,11 +109,11 @@ class TestWorker(RQTestCase): raise q = Queue() - result = q.enqueue(create_file, SENTINEL_FILE) + job = q.enqueue(create_file, SENTINEL_FILE) # Here, we cancel the job, so the sentinel file may not be created assert q.count == 1 - result.cancel() + job.cancel() assert q.count == 1 w = Worker([q])