diff --git a/rq/job.py b/rq/job.py index de2b007..9e9f207 100644 --- a/rq/job.py +++ b/rq/job.py @@ -112,31 +112,43 @@ class Job(object): job._dependency_id = depends_on.id if isinstance(depends_on, Job) else depends_on return job - def _get_status(self): + def get_status(self): self._status = as_text(self.connection.hget(self.key, 'status')) return self._status - def _set_status(self, status): + def _get_status(self): + raise DeprecationWarning( + "job.status is deprecated. Use job.get_status() instead" + ) + return self.get_status() + + def set_status(self, status): self._status = status self.connection.hset(self.key, 'status', self._status) + def _set_status(self, status): + raise DeprecationWarning( + "job.status is deprecated. Use job.set_status() instead" + ) + self.set_status(status) + status = property(_get_status, _set_status) @property def is_finished(self): - return self.status == Status.FINISHED + return self.get_status() == Status.FINISHED @property def is_queued(self): - return self.status == Status.QUEUED + return self.get_status() == Status.QUEUED @property def is_failed(self): - return self.status == Status.FAILED + return self.get_status() == Status.FAILED @property def is_started(self): - return self.status == Status.STARTED + return self.get_status() == Status.STARTED @property def dependency(self): diff --git a/rq/queue.py b/rq/queue.py index d4cbb54..49d43d7 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -160,7 +160,7 @@ class Queue(object): while True: try: pipe.watch(depends_on.key) - if depends_on.status != Status.FINISHED: + if depends_on.get_status() != Status.FINISHED: job.register_dependency() job.save() return job @@ -383,7 +383,7 @@ class FailedQueue(Queue): if self.remove(job) == 0: raise InvalidJobOperationError('Cannot requeue non-failed jobs.') - job.status = Status.QUEUED + job.set_status(Status.QUEUED) job.exc_info = None q = Queue(job.origin, connection=self.connection) q.enqueue_job(job) diff --git a/rq/worker.py b/rq/worker.py index c015dfa..df4812c 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -352,7 +352,7 @@ class Worker(object): self.set_current_job_id(job.id) # Use the public setter here, to immediately update Redis - job.status = Status.STARTED + job.set_status(Status.STARTED) self.log.info('%s: %s (%s)' % (green(queue.name), blue(job.description), job.id)) @@ -361,7 +361,7 @@ class Worker(object): self.heartbeat() self.set_current_job_id(None) - if job.status == Status.FINISHED: + if job.get_status() == Status.FINISHED: queue.enqueue_dependents(job) did_perform_work = True @@ -476,7 +476,7 @@ class Worker(object): except Exception: # Use the public setter here, to immediately update Redis - job.status = Status.FAILED + job.set_status(Status.FAILED) self.handle_exception(job, *sys.exc_info()) return False diff --git a/tests/test_queue.py b/tests/test_queue.py index 75a97db..6dde3ea 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -258,7 +258,7 @@ class TestQueue(RQTestCase): """Enqueueing a job sets its status to "queued".""" q = Queue() job = q.enqueue(say_hello) - self.assertEqual(job.status, Status.QUEUED) + self.assertEqual(job.get_status(), Status.QUEUED) def test_all_queues(self): """All queues""" @@ -316,7 +316,7 @@ class TestQueue(RQTestCase): self.assertEqual(q.job_ids, []) # Jobs dependent on finished jobs are immediately enqueued - parent_job.status = Status.FINISHED + parent_job.set_status(Status.FINISHED) parent_job.save() job = q.enqueue_call(say_hello, depends_on=parent_job) self.assertEqual(q.job_ids, [job.id]) @@ -332,7 +332,7 @@ class TestQueue(RQTestCase): self.assertEqual(job.timeout, 123) # Jobs dependent on finished jobs are immediately enqueued - parent_job.status = Status.FINISHED + parent_job.set_status(Status.FINISHED) parent_job.save() job = q.enqueue_call(say_hello, depends_on=parent_job, timeout=123) self.assertEqual(q.job_ids, [job.id]) @@ -394,7 +394,7 @@ class TestFailedQueue(RQTestCase): get_failed_queue().requeue(job.id) job = Job.fetch(job.id) - self.assertEqual(job.status, Status.QUEUED) + self.assertEqual(job.get_status(), Status.QUEUED) def test_enqueue_preserves_result_ttl(self): """Enqueueing persists result_ttl.""" diff --git a/tests/test_worker.py b/tests/test_worker.py index a7fa320..b7147fe 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -214,14 +214,14 @@ class TestWorker(RQTestCase): w = Worker([q]) job = q.enqueue(say_hello) - self.assertEqual(job.status, Status.QUEUED) + self.assertEqual(job.get_status(), Status.QUEUED) self.assertEqual(job.is_queued, True) self.assertEqual(job.is_finished, False) self.assertEqual(job.is_failed, False) w.work(burst=True) job = Job.fetch(job.id) - self.assertEqual(job.status, Status.FINISHED) + self.assertEqual(job.get_status(), Status.FINISHED) self.assertEqual(job.is_queued, False) self.assertEqual(job.is_finished, True) self.assertEqual(job.is_failed, False) @@ -230,7 +230,7 @@ class TestWorker(RQTestCase): job = q.enqueue(div_by_zero, args=(1,)) w.work(burst=True) job = Job.fetch(job.id) - self.assertEqual(job.status, Status.FAILED) + self.assertEqual(job.get_status(), Status.FAILED) self.assertEqual(job.is_queued, False) self.assertEqual(job.is_finished, False) self.assertEqual(job.is_failed, True) @@ -243,13 +243,13 @@ class TestWorker(RQTestCase): job = q.enqueue_call(say_hello, depends_on=parent_job) w.work(burst=True) job = Job.fetch(job.id) - self.assertEqual(job.status, Status.FINISHED) + self.assertEqual(job.get_status(), Status.FINISHED) parent_job = q.enqueue(div_by_zero) job = q.enqueue_call(say_hello, depends_on=parent_job) w.work(burst=True) job = Job.fetch(job.id) - self.assertNotEqual(job.status, Status.FINISHED) + self.assertNotEqual(job.get_status(), Status.FINISHED) def test_get_current_job(self): """Ensure worker.get_current_job() works properly"""