extract `safe_fetch_job` method

main
Alex Morega 12 years ago committed by Vincent Driessen
parent 0f804e07ae
commit ef0f04bff6

@ -64,15 +64,7 @@ class Queue(object):
"""Returns whether the current queue is empty.""" """Returns whether the current queue is empty."""
return self.count == 0 return self.count == 0
@property def safe_fetch_job(self, job_id):
def job_ids(self):
"""Returns a list of all job IDS in the queue."""
return self.connection.lrange(self.key, 0, -1)
@property
def jobs(self):
"""Returns a list of all (valid) jobs in the queue."""
def safe_fetch(job_id):
try: try:
job = Job.safe_fetch(job_id, connection=self.connection) job = Job.safe_fetch(job_id, connection=self.connection)
except NoSuchJobError: except NoSuchJobError:
@ -82,7 +74,15 @@ class Queue(object):
return None return None
return job return job
return compact([safe_fetch(job_id) for job_id in self.job_ids]) @property
def job_ids(self):
"""Returns a list of all job IDS in the queue."""
return self.connection.lrange(self.key, 0, -1)
@property
def jobs(self):
"""Returns a list of all (valid) jobs in the queue."""
return compact([self.safe_fetch_job(job_id) for job_id in self.job_ids])
@property @property
def count(self): def count(self):

Loading…
Cancel
Save