Minor refactoring to make the to-failed queue code a bit more readable.

This commit is contained in:
Vincent Driessen 2012-02-13 16:51:47 +01:00
parent 11c7dbb376
commit 1a8b80604d
2 changed files with 10 additions and 11 deletions

View File

@ -85,10 +85,15 @@ class Queue(object):
job = Job.for_call(f, *args, **kwargs)
return self.enqueue_job(job)
def enqueue_job(self, job):
"""Enqueues a job for delayed execution."""
job.origin = self.name
job.enqueued_at = times.now()
def enqueue_job(self, job, to_failed=False):
"""Enqueues a job for delayed execution.
If the `to_failed` argument is `True`, it won't update the origin or
enqueued_at properties.
"""
if not to_failed:
job.origin = self.name
job.enqueued_at = times.now()
job.save()
self.push_job_id(job.id)
return job

View File

@ -324,13 +324,7 @@ class Worker(object):
job.ended_at = times.now()
job.exc_info = traceback.format_exc()
# ------ REFACTOR THIS -------------------------
job.save()
# ...and put the job on the failed queue
fq.push_job_id(job.id)
# ------ UNTIL HERE ----------------------------
# (should be as easy as fq.enqueue(job) or so)
fq.enqueue_job(job, to_failed=True)
return False
else:
if rv is None: