Make FailedQueue a full subclass of Queue.

We will add special methods on it in the future.

This fixes #33.
This commit is contained in:
Vincent Driessen 2012-02-15 15:29:26 +01:00
parent 6f05e03293
commit d64ad225eb
2 changed files with 13 additions and 7 deletions

View File

@ -108,13 +108,13 @@ class Queue(object):
job = Job.for_call(f, *args, **kwargs) job = Job.for_call(f, *args, **kwargs)
return self.enqueue_job(job) 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. """Enqueues a job for delayed execution.
If the `to_failed` argument is `True`, it won't update the origin or If the `set_meta_data` argument is `True` (default), it will update
enqueued_at properties. the properties `origin` and `enqueued_at`.
""" """
if not to_failed: if set_meta_data:
job.origin = self.name job.origin = self.name
job.enqueued_at = times.now() job.enqueued_at = times.now()
job.save() job.save()
@ -221,3 +221,9 @@ class Queue(object):
def __str__(self): def __str__(self):
return '<Queue \'%s\'>' % (self.name,) return '<Queue \'%s\'>' % (self.name,)
class FailedQueue(Queue):
def __init__(self):
super(FailedQueue, self).__init__('failed')

View File

@ -14,7 +14,7 @@ try:
Logger = Logger # Does nothing except it shuts up pyflakes annoying error Logger = Logger # Does nothing except it shuts up pyflakes annoying error
except ImportError: except ImportError:
from logging import Logger from logging import Logger
from .queue import Queue from .queue import Queue, FailedQueue
from .proxy import conn from .proxy import conn
from .utils import make_colorizer from .utils import make_colorizer
from .exceptions import NoQueueError, UnpickleError from .exceptions import NoQueueError, UnpickleError
@ -92,7 +92,7 @@ class Worker(object):
self._horse_pid = 0 self._horse_pid = 0
self._stopped = False self._stopped = False
self.log = Logger('worker') self.log = Logger('worker')
self.failed_queue = Queue('failed') self.failed_queue = FailedQueue()
def validate_queues(self): # noqa def validate_queues(self): # noqa
@ -336,7 +336,7 @@ class Worker(object):
job.ended_at = times.now() job.ended_at = times.now()
job.exc_info = traceback.format_exc() job.exc_info = traceback.format_exc()
fq.enqueue_job(job, to_failed=True) fq.enqueue_job(job, set_meta_data=False)
return False return False
else: else:
if rv is None: if rv is None: