-
Notifications
You must be signed in to change notification settings - Fork 79
adding User.jobs() #2035
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
adding User.jobs() #2035
Changes from 6 commits
da218e8
83d0b2b
747059c
b6ab4ed
6b3c252
c2582e9
d00e117
88367bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (c) 2014--, The Qiita Development Team. | ||
# | ||
# Distributed under the terms of the BSD 3-clause License. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
# ----------------------------------------------------------------------------- | ||
from unittest import TestCase, main | ||
from os.path import exists, isdir | ||
from os import remove | ||
from shutil import rmtree | ||
|
||
from qiita_core.util import qiita_test_checker | ||
import qiita_db as qdb | ||
from qiita_pet.handlers.api_proxy.user import (user_jobs_get_req) | ||
|
||
|
||
@qiita_test_checker() | ||
class TestSUserAPI(TestCase): | ||
def setUp(self): | ||
self._clean_up_files = [] | ||
|
||
def tearDown(self): | ||
for fp in self._clean_up_files: | ||
if exists(fp): | ||
if isdir(fp): | ||
rmtree(fp) | ||
else: | ||
remove(fp) | ||
|
||
def test_user_jobs_get_req(self): | ||
obs = user_jobs_get_req(qdb.user.User('shared@foo.bar')) | ||
exp = { | ||
'status': 'success', | ||
'message': '', | ||
'jobs': [ | ||
{'id': 'd19f76ee-274e-4c1b-b3a2-a12d73507c55', | ||
'status': 'error', | ||
'heartbeat': '2015-11-22 21:30:00', | ||
'params': { | ||
'reference': 1, | ||
'similarity': 0.97, | ||
'sortmerna_e_value': 1, | ||
'sortmerna_max_pos': 10000, | ||
'input_data': 2, | ||
'threads': 1, | ||
'sortmerna_coverage': 0.97}, | ||
'name': 'Pick closed-reference OTUs', | ||
'processing_job_workflow_id': ''}, | ||
{'id': 'b72369f9-a886-4193-8d3d-f7b504168e75', | ||
'status': 'success', | ||
'heartbeat': '2015-11-22 21:15:00', | ||
'params': { | ||
'max_barcode_errors': 1.5, | ||
'sequence_max_n': 0, | ||
'max_bad_run_length': 3, | ||
'phred_offset': u'auto', | ||
'rev_comp': False, | ||
'phred_quality_threshold': 3, | ||
'input_data': 1, | ||
'rev_comp_barcode': False, | ||
'rev_comp_mapping_barcodes': True, | ||
'min_per_read_length_fraction': 0.75, | ||
'barcode_type': u'golay_12'}, | ||
'name': 'Split libraries FASTQ', | ||
'processing_job_workflow_id': 1}]} | ||
self.assertEqual(obs, exp) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright (c) 2014--, The Qiita Development Team. | ||
# | ||
# Distributed under the terms of the BSD 3-clause License. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
# ----------------------------------------------------------------------------- | ||
from __future__ import division | ||
|
||
from qiita_core.util import execute_as_transaction | ||
|
||
|
||
@execute_as_transaction | ||
def user_jobs_get_req(user): | ||
"""Gets the json of jobs | ||
|
||
Parameters | ||
---------- | ||
prep_id : int | ||
PrepTemplate id to get info for | ||
user_id : str | ||
User requesting the sample template info | ||
|
||
Returns | ||
------- | ||
dict of objects | ||
{'status': status, | ||
'message': message, | ||
'template': {sample: {column: value, ...}, ...} | ||
""" | ||
|
||
response = [] | ||
cmds = {} | ||
for j in user.jobs(): | ||
cmd = j.command | ||
if cmd not in cmds: | ||
cmds[cmd] = cmd | ||
name = cmds[cmd].name | ||
hb = j.heartbeat | ||
hb = "" if hb is None else hb.strftime("%Y-%m-%d %H:%M:%S") | ||
pjw = j.processing_job_worflow | ||
wid = '' if pjw is None else pjw.id | ||
response.append({ | ||
'id': j.id, | ||
'name': name, | ||
'params': j.parameters.values, | ||
'status': j.status, | ||
'heartbeat': hb, | ||
'processing_job_workflow_id': wid}) | ||
|
||
return {'status': 'success', | ||
'message': '', | ||
'jobs': response} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from tornado.web import authenticated, HTTPError | ||
from tornado.gen import coroutine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are flake8 errors because this import is not being used. |
||
from future.utils import viewitems | ||
from wtforms import Form, StringField, validators | ||
|
||
from qiita_pet.handlers.base_handlers import BaseHandler | ||
from qiita_pet.handlers.api_proxy import user_jobs_get_req | ||
from qiita_db.user import User | ||
from qiita_db.logger import LogEntry | ||
from qiita_db.exceptions import QiitaDBUnknownIDError, QiitaDBError | ||
|
@@ -185,3 +187,11 @@ def post(self): | |
|
||
self.render("user_messages.html", | ||
messages=self.current_user.messages()) | ||
|
||
|
||
class UserJobs(BaseHandler): | ||
@authenticated | ||
@coroutine | ||
def get(self): | ||
response = user_jobs_get_req(self.current_user) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this executes as a transaction and has the potential to block as it is performing IO. Should this method be a tornado There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this needs take the result of a |
||
self.write(response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a valid situation in which the same command will appear multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, multiple and the idea of cache; basically, the command is the definition of the command (split libs, demux, etc) and the job is the command with the specific params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how this caches anything though?
cmds
is reset prior to the forloop so the only compute that is avoided is the assignment of a value to a key in a dict?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...on closer inspection, it doesn't look like
cmds
is needed at all