Skip to content

Commit

Permalink
extract safe_fetch_job method
Browse files Browse the repository at this point in the history
  • Loading branch information
mgax authored and nvie committed Apr 19, 2013
1 parent 0f804e0 commit ef0f04b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions rq/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def is_empty(self):
"""Returns whether the current queue is empty."""
return self.count == 0

def safe_fetch_job(self, job_id):
try:
job = Job.safe_fetch(job_id, connection=self.connection)
except NoSuchJobError:
self.remove(job_id)
return None
except UnpickleError:
return None
return job

@property
def job_ids(self):
"""Returns a list of all job IDS in the queue."""
Expand All @@ -72,17 +82,7 @@ def job_ids(self):
@property
def jobs(self):
"""Returns a list of all (valid) jobs in the queue."""
def safe_fetch(job_id):
try:
job = Job.safe_fetch(job_id, connection=self.connection)
except NoSuchJobError:
self.remove(job_id)
return None
except UnpickleError:
return None
return job

return compact([safe_fetch(job_id) for job_id in self.job_ids])
return compact([self.safe_fetch_job(job_id) for job_id in self.job_ids])

@property
def count(self):
Expand Down

0 comments on commit ef0f04b

Please sign in to comment.