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.
This commit is contained in:
Vincent Driessen 2012-02-15 15:31:15 +01:00
parent d64ad225eb
commit 240d2d941d
2 changed files with 12 additions and 6 deletions

View File

@ -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)

View File

@ -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: