From 865efd6e8c9de1b9ab10ab86b37133c65c1dee8b Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sat, 26 Jul 2014 08:54:52 +0200 Subject: [PATCH] Leave setting the state to the worker, not the Job itself. Should fix #389. --- rq/job.py | 4 ---- rq/worker.py | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) 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)