diff --git a/rq/job.py b/rq/job.py index e8203e5..e531745 100644 --- a/rq/job.py +++ b/rq/job.py @@ -470,13 +470,9 @@ class Job(object): """Invokes the job function with the job arguments.""" _job_stack.push(self.id) try: - self.set_status(Status.STARTED) self._result = self.func(*self.args, **self.kwargs) - self.set_status(Status.FINISHED) - self.ended_at = utcnow() finally: assert self.id == _job_stack.pop() - return self._result def get_ttl(self, default_ttl=None): diff --git a/rq/worker.py b/rq/worker.py index 853ad21..59c1624 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -483,6 +483,7 @@ class Worker(object): with self.connection._pipeline() as pipeline: try: + job.set_status(Status.STARTED) with self.death_penalty_class(job.timeout or self.queue_class.DEFAULT_TIMEOUT): rv = job.perform() @@ -494,6 +495,8 @@ class Worker(object): result_ttl = job.get_ttl(self.default_result_ttl) if result_ttl != 0: + job.ended_at = utcnow() + job._status = Status.FINISHED job.save(pipeline=pipeline) job.cleanup(result_ttl, pipeline=pipeline)