Skip to content

Commit

Permalink
Merge 12406cc into b9b2caa
Browse files Browse the repository at this point in the history
  • Loading branch information
antgonza committed Jan 3, 2017
2 parents b9b2caa + 12406cc commit 3d429e2
Show file tree
Hide file tree
Showing 20 changed files with 640 additions and 270 deletions.
19 changes: 19 additions & 0 deletions qiita_db/processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,25 @@ def outputs(self):
name: qdb.artifact.Artifact(aid)
for aid, name in qdb.sql_connection.TRN.execute_fetchindex()}

@property
def processing_job_worflow(self):
"""The processing job worflow
Returns
-------
ProcessingWorkflow
The processing job workflow the job
"""
with qdb.sql_connection.TRN:
sql = """SELECT processing_job_workflow_id
FROM qiita.processing_job_workflow_root
WHERE processing_job_id = %s"""
qdb.sql_connection.TRN.add(sql, [self.id])
r = qdb.sql_connection.TRN.execute_fetchindex()

return (None if not r
else qdb.processing_job.ProcessingWorkflow(r[0][0]))


class ProcessingWorkflow(qdb.base.QiitaObject):
"""Models a workflow defined by the user
Expand Down
12 changes: 12 additions & 0 deletions qiita_db/test/test_processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ def test_outputs(self):
[afp for _, afp, _ in
qdb.artifact.Artifact(exp_artifact_count).filepaths])

def test_processing_job_worflow(self):
# testing None
job = qdb.processing_job.ProcessingJob(
"063e553b-327c-4818-ab4a-adfe58e49860")
self.assertIsNone(job.processing_job_worflow)

# testing actual workflow
job = qdb.processing_job.ProcessingJob(
"b72369f9-a886-4193-8d3d-f7b504168e75")
self.assertEqual(job.processing_job_worflow,
qdb.processing_job.ProcessingWorkflow(1))


@qiita_test_checker()
class ProcessingWorkflowTests(TestCase):
Expand Down
11 changes: 11 additions & 0 deletions qiita_db/test/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,16 @@ def test_user_artifacts(self):
qdb.artifact.Artifact(7)]}
self.assertEqual(obs, exp)

def test_jobs(self):
PJ = qdb.processing_job.ProcessingJob
# generates expected jobs
jobs = qdb.user.User('shared@foo.bar').jobs()
self.assertEqual(jobs, [
PJ('d19f76ee-274e-4c1b-b3a2-a12d73507c55'),
PJ('b72369f9-a886-4193-8d3d-f7b504168e75')])

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

if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions qiita_db/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class User(qdb.base.QiitaObject):
private_analyses
shared_analyses
unread_messages
jobs
Methods
-------
Expand Down Expand Up @@ -660,6 +661,27 @@ def delete_messages(self, messages):
qdb.sql_connection.TRN.add(sql)
qdb.sql_connection.TRN.execute()

def jobs(self):
"""Return jobs created by the user
Parameters
----------
Returns
-------
list of ProcessingJob
"""
with qdb.sql_connection.TRN:
sql_info = [self._id]
sql = """SELECT processing_job_id
FROM qiita.processing_job
WHERE email = %s
ORDER BY heartbeat DESC"""
qdb.sql_connection.TRN.add(sql, sql_info)
return [qdb.processing_job.ProcessingJob(p[0])
for p in qdb.sql_connection.TRN.execute_fetchindex()]


def validate_email(email):
"""Validates an email
Expand Down
3 changes: 2 additions & 1 deletion qiita_pet/handlers/api_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
list_options_handler_get_req, workflow_handler_post_req,
workflow_handler_patch_req, workflow_run_post_req,
job_ajax_get_req)
from .user import (user_jobs_get_req)

__version__ = "0.2.0-dev"

Expand All @@ -64,4 +65,4 @@
'workflow_handler_patch_req', 'workflow_run_post_req',
'job_ajax_get_req', 'artifact_patch_request',
'sample_template_patch_request',
'get_sample_template_processing_status']
'get_sample_template_processing_status', 'user_jobs_get_req']
71 changes: 71 additions & 0 deletions qiita_pet/handlers/api_proxy/tests/test_user.py
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()
55 changes: 55 additions & 0 deletions qiita_pet/handlers/api_proxy/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -----------------------------------------------------------------------------
# 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, limit=10):
"""Gets the json of jobs
Parameters
----------
user : User
The user from which you want to return all jobs
limit : int, optional
Maximum jobs to send, negative values will return all
Returns
-------
dict of objects
{'status': status,
'message': message,
'template': {{column: value, ...}, ...}
"""

response = []
cmds = {}
for i, j in enumerate(user.jobs()):
if i == limit:
break
cmd = j.command
if cmd not in cmds:
cmds[cmd] = cmd
ccmd = cmds[cmd]
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': ccmd.name,
'params': j.parameters.values,
'status': j.status,
'heartbeat': hb,
'processing_job_workflow_id': wid})

return {'status': 'success',
'message': '',
'jobs': response}
8 changes: 8 additions & 0 deletions qiita_pet/handlers/user_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand Down Expand Up @@ -185,3 +186,10 @@ def post(self):

self.render("user_messages.html",
messages=self.current_user.messages())


class UserJobs(BaseHandler):
@authenticated
def get(self):
response = user_jobs_get_req(self.current_user)
self.write(response)
14 changes: 14 additions & 0 deletions qiita_pet/static/css/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
div.qiita-main {
position: relative;
height: 100%;
width: 100%;
}

#qiita-processing {
position: absolute;
height: 100%;
width: 0%;
right: 0;
top: 0;
}

#template-content{
padding: 10px;
height: 100%;
Expand Down
17 changes: 16 additions & 1 deletion qiita_pet/static/js/qiita.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function show_hide(div) {
$('#' + div).toggle();
}


function delete_analysis(aname, analysis_id) {
if (confirm('Are you sure you want to delete analysis: ' + aname + '?')) {
var form = $("<form>")
Expand All @@ -58,3 +57,19 @@ function delete_analysis(aname, analysis_id) {
form.submit();
}
}

function show_hide_process_list() {
if ($("#qiita-main").width() == $("#qiita-main").parent().width()) {
$("#qiita-main").width("76%");
$("#user-studies-table").width("76%");
$("#studies-table").width("76%");
$("#qiita-processing").width("24%");
$("#qiita-processing").show();
} else {
$("#qiita-main").width("100%");
$("#user-studies-table").width("100%");
$("#studies-table").width("100%");
$("#qiita-processing").width("0%");
$("#qiita-processing").hide();
}
}
8 changes: 8 additions & 0 deletions qiita_pet/static/vendor/js/vue.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions qiita_pet/templates/admin_approval.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends sitebase.html %}
{% block head %}
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/jquery.dataTables.css" type="text/css">
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.dataTables.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {
Expand Down
4 changes: 0 additions & 4 deletions qiita_pet/templates/error_log.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
{% from future.utils import viewitems %}
{% from qiita_core.qiita_settings import qiita_config %}

<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/jquery.dataTables.css" type="text/css">

<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.dataTables.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$('#error-table').dataTable({"order": [[1, "asc"]]});
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% end %}

{%block content %}
<div id="jumbotron" class="jumbotron">
<div id="jumbotron" class="jumbotron" style="border-radius: 10px; padding: 30px">
<h1>{% raw portal_styling.index_header%}</h1>
{% raw portal_styling.index_text%}
</div>
Expand Down
4 changes: 2 additions & 2 deletions qiita_pet/templates/list_studies.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
cursor: pointer;
}
</style>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.dataTables.min.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.dataTables.plugin.natural.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/moi.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/select2.min.js"></script>
<script src="{% raw qiita_config.portal_dir %}/static/js/sharing.js"></script>
Expand Down Expand Up @@ -302,6 +300,8 @@ <h3 class="gray-msg">Other Studies</h3>
</tr>
</thead>
</table>
</div>
</div>
<!--Abstract Modal-->
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="study-abstract-modal">
<div class="modal-dialog modal-med">
Expand Down
2 changes: 0 additions & 2 deletions qiita_pet/templates/portals_edit.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends sitebase.html%}

{%block head%}
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/jquery.dataTables.css" type="text/css">
<style type="text/css">
.navlist li
{
Expand All @@ -19,7 +18,6 @@
white-space: nowrap;
}
</style>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
function check_submit(action) {
//disable submit buttons
Expand Down
Loading

0 comments on commit 3d429e2

Please sign in to comment.