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

main
Vincent Driessen 13 years ago
parent 11c7dbb376
commit 1a8b80604d

@ -85,10 +85,15 @@ 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): def enqueue_job(self, job, to_failed=False):
"""Enqueues a job for delayed execution.""" """Enqueues a job for delayed execution.
job.origin = self.name
job.enqueued_at = times.now() 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() job.save()
self.push_job_id(job.id) self.push_job_id(job.id)
return job return job

@ -324,13 +324,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()
# ------ REFACTOR THIS ------------------------- fq.enqueue_job(job, to_failed=True)
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)
return False return False
else: else:
if rv is None: if rv is None:

Loading…
Cancel
Save