From d64ad225eb1c96c593ee7d35ee18811bb9743b23 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 15 Feb 2012 15:29:26 +0100 Subject: [PATCH] Make FailedQueue a full subclass of Queue. We will add special methods on it in the future. This fixes #33. --- rq/queue.py | 14 ++++++++++---- rq/worker.py | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 9c33be6..92041dd 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -108,13 +108,13 @@ class Queue(object): job = Job.for_call(f, *args, **kwargs) return self.enqueue_job(job) - def enqueue_job(self, job, to_failed=False): + def enqueue_job(self, job, set_meta_data=True): """Enqueues a job for delayed execution. - If the `to_failed` argument is `True`, it won't update the origin or - enqueued_at properties. + If the `set_meta_data` argument is `True` (default), it will update + the properties `origin` and `enqueued_at`. """ - if not to_failed: + if set_meta_data: job.origin = self.name job.enqueued_at = times.now() job.save() @@ -221,3 +221,9 @@ class Queue(object): def __str__(self): return '' % (self.name,) + + +class FailedQueue(Queue): + def __init__(self): + super(FailedQueue, self).__init__('failed') + diff --git a/rq/worker.py b/rq/worker.py index 6c4eb43..37e6e12 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -14,7 +14,7 @@ try: Logger = Logger # Does nothing except it shuts up pyflakes annoying error except ImportError: from logging import Logger -from .queue import Queue +from .queue import Queue, FailedQueue from .proxy import conn from .utils import make_colorizer from .exceptions import NoQueueError, UnpickleError @@ -92,7 +92,7 @@ class Worker(object): self._horse_pid = 0 self._stopped = False self.log = Logger('worker') - self.failed_queue = Queue('failed') + self.failed_queue = FailedQueue() def validate_queues(self): # noqa @@ -336,7 +336,7 @@ class Worker(object): job.ended_at = times.now() job.exc_info = traceback.format_exc() - fq.enqueue_job(job, to_failed=True) + fq.enqueue_job(job, set_meta_data=False) return False else: if rv is None: