From acdeff385daf5157e6646dfb47a02f92e6b19b3a Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 5 Feb 2023 19:24:15 +0700 Subject: [PATCH] Use job.return_value() instead of job.result when processing callbacks (#1801) * Use job.return_value() instead of job.result when processing callbacks * job.return_value() should also support Redis server < 5. --- rq/job.py | 8 ++++++++ rq/queue.py | 4 ++-- tests/test_callbacks.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rq/job.py b/rq/job.py index 9bc08f1..81ed98e 100644 --- a/rq/job.py +++ b/rq/job.py @@ -743,6 +743,14 @@ class Job: self._cached_result = None if not self.supports_redis_streams: + if self._result is not None: + return self._result + + rv = self.connection.hget(self.key, 'result') + if rv is not None: + # cache the result + self._result = self.serializer.loads(rv) + return self._result return None if not self._cached_result: diff --git a/rq/queue.py b/rq/queue.py index 3b3e7b0..bde1ceb 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -1035,10 +1035,10 @@ class Queue: pipeline.execute() if job.failure_callback: - job.failure_callback(job, self.connection, *sys.exc_info()) + job.failure_callback(job, self.connection, *sys.exc_info()) # type: ignore else: if job.success_callback: - job.success_callback(job, self.connection, job.result) + job.success_callback(job, self.connection, job.return_value()) # type: ignore return job diff --git a/tests/test_callbacks.py b/tests/test_callbacks.py index 8d8edc7..680ee38 100644 --- a/tests/test_callbacks.py +++ b/tests/test_callbacks.py @@ -90,7 +90,7 @@ class WorkerCallbackTestCase(RQTestCase): self.assertEqual(job.get_status(), JobStatus.FINISHED) self.assertEqual( self.testconn.get('success_callback:%s' % job.id).decode(), - job.result + job.return_value() ) job = queue.enqueue(div_by_zero, on_success=save_result)