From 240d2d941d6185f90eec4ba37c8c1c9eb4df1ac7 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 15 Feb 2012 15:31:15 +0100 Subject: [PATCH] Extracted method. This makes the act of moving failed jobs to the failed queue responsibility of the FailedQueue itself, not of the Worker. This fixes #32. --- rq/queue.py | 11 +++++++++++ rq/worker.py | 7 +------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 92041dd..9bc09e8 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 37e6e12..26fc5d6 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: