diff --git a/rq/queue.py b/rq/queue.py index 92041ddb..9bc09e85 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -227,3 +227,14 @@ class FailedQueue(Queue): def __init__(self): super(FailedQueue, self).__init__('failed') + def quarantine(self, job, exc_info): + """Puts the given Job in quarantine (i.e. put it on the failed + queue). + + This is different from normal job enqueueing, since certain meta data + must not be overridden (e.g. `origin` or `enqueued_at`) and other meta + data must be inserted (`ended_at` and `exc_info`). + """ + job.ended_at = times.now() + job.exc_info = exc_info + return self.enqueue_job(job, set_meta_data=False) diff --git a/rq/worker.py b/rq/worker.py index 37e6e128..26fc5d65 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -3,7 +3,6 @@ import os import errno import random import time -import times import procname import socket import signal @@ -332,11 +331,7 @@ class Worker(object): self.log.exception(red(str(e))) self.log.warning('Moving job to %s queue.' % fq.name) - # Store the exception information... - job.ended_at = times.now() - job.exc_info = traceback.format_exc() - - fq.enqueue_job(job, set_meta_data=False) + fq.quarantine(job, exc_info=traceback.format_exc()) return False else: if rv is None: