Skip to content

limiting number of jobs retrieved #2134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions qiita_db/test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,20 @@ def test_jobs_all(self):
PJ = qdb.processing_job.ProcessingJob
ignore_status = []
# generates expected jobs
jobs = qdb.user.User('shared@foo.bar').jobs(ignore_status)
jobs = qdb.user.User('shared@foo.bar').jobs(
ignore_status=ignore_status)
self.assertEqual(jobs, [
PJ('d19f76ee-274e-4c1b-b3a2-a12d73507c55'),
PJ('b72369f9-a886-4193-8d3d-f7b504168e75')])

# just one job
self.assertEqual(qdb.user.User('shared@foo.bar').jobs(
limit=1, ignore_status=ignore_status), [
PJ('d19f76ee-274e-4c1b-b3a2-a12d73507c55')])

# no jobs
self.assertEqual(qdb.user.User('admin@foo.bar').jobs(
ignore_status), [])
ignore_status=ignore_status), [])

def test_jobs_defaults(self):
PJ = qdb.processing_job.ProcessingJob
Expand Down
12 changes: 7 additions & 5 deletions qiita_db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,14 @@ def delete_messages(self, messages):
qdb.sql_connection.TRN.add(sql)
qdb.sql_connection.TRN.execute()

def jobs(self, ignore_status=['success']):
def jobs(self, limit=30, ignore_status=['success']):
"""Return jobs created by the user

Parameters
----------
ignore_status, list of str
limit : int, optional
max number of rows to return
ignore_status: list of str, optional
don't retieve jobs that have one of these status

Returns
Expand All @@ -683,10 +685,10 @@ def jobs(self, ignore_status=['success']):
"""

if ignore_status:
sql_info = [self._id, tuple(ignore_status)]
sql_info = [self._id, tuple(ignore_status), limit]
sql += " AND processing_job_status NOT IN %s"
else:
sql_info = [self._id]
sql_info = [self._id, limit]

sql += """
ORDER BY CASE processing_job_status
Expand All @@ -696,7 +698,7 @@ def jobs(self, ignore_status=['success']):
WHEN 'waiting' THEN 4
WHEN 'error' THEN 5
WHEN 'success' THEN 6
END, heartbeat DESC"""
END, heartbeat DESC LIMIT %s"""

qdb.sql_connection.TRN.add(sql, sql_info)
return [qdb.processing_job.ProcessingJob(p[0])
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/handlers/api_proxy/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def user_jobs_get_req(user, limit=30):
"""

response = []
for i, j in enumerate(user.jobs()):
for i, j in enumerate(user.jobs(limit=limit)):
name = j.command.name
hb = j.heartbeat
hb = "" if hb is None else hb.strftime("%Y-%m-%d %H:%M:%S")
Expand Down