From 1a8b80604d98314351632c61553d281a7885d09a Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Mon, 13 Feb 2012 16:51:47 +0100 Subject: [PATCH] Minor refactoring to make the to-failed queue code a bit more readable. --- rq/queue.py | 13 +++++++++---- rq/worker.py | 8 +------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index efccff86..3ab16d41 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -85,10 +85,15 @@ class Queue(object): job = Job.for_call(f, *args, **kwargs) return self.enqueue_job(job) - def enqueue_job(self, job): - """Enqueues a job for delayed execution.""" - job.origin = self.name - job.enqueued_at = times.now() + def enqueue_job(self, job, to_failed=False): + """Enqueues a job for delayed execution. + + If the `to_failed` argument is `True`, it won't update the origin or + enqueued_at properties. + """ + if not to_failed: + job.origin = self.name + job.enqueued_at = times.now() job.save() self.push_job_id(job.id) return job diff --git a/rq/worker.py b/rq/worker.py index c56cb533..e3863ed5 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -324,13 +324,7 @@ class Worker(object): job.ended_at = times.now() job.exc_info = traceback.format_exc() - # ------ REFACTOR THIS ------------------------- - job.save() - # ...and put the job on the failed queue - fq.push_job_id(job.id) - # ------ UNTIL HERE ---------------------------- - # (should be as easy as fq.enqueue(job) or so) - + fq.enqueue_job(job, to_failed=True) return False else: if rv is None: