Skip to content

Commit

Permalink
Merge af223ed into 7c798a1
Browse files Browse the repository at this point in the history
  • Loading branch information
josenavas committed Apr 18, 2016
2 parents 7c798a1 + af223ed commit 9d734c0
Show file tree
Hide file tree
Showing 22 changed files with 1,458 additions and 1,556 deletions.
11 changes: 5 additions & 6 deletions qiita_db/handlers/processing_job.py
Expand Up @@ -110,13 +110,12 @@ def post(self, job_id):
"""
with qdb.sql_connection.TRN:
job = _get_job(job_id)
job_status = job.status
if job_status != 'running':
raise HTTPError(403, 'Job in a non-running state')
else:
payload = loads(self.request.body)
step = payload['step']
payload = loads(self.request.body)
step = payload['step']
try:
job.step = step
except qdb.exceptions.QiitaDBOperationNotPermittedError as e:
raise HTTPError(403, str(e))

self.finish()

Expand Down
3 changes: 2 additions & 1 deletion qiita_db/handlers/tests/test_processing_job.py
Expand Up @@ -119,7 +119,8 @@ def test_post_non_running_job(self):
'/qiita_db/jobs/063e553b-327c-4818-ab4a-adfe58e49860/step/',
payload, headers=self.header)
self.assertEqual(obs.code, 403)
self.assertEqual(obs.body, 'Job in a non-running state')
self.assertEqual(obs.body, "Cannot change the step of a job whose "
"status is not 'running'")

def test_post(self):
payload = dumps({'step': 'Step 1 of 4: demultiplexing'})
Expand Down
43 changes: 22 additions & 21 deletions qiita_plugins/biom_type/biom_type_plugin/plugin.py
Expand Up @@ -12,7 +12,7 @@
import traceback
import sys

from qiita_client import QiitaClient, format_payload
from qiita_client import QiitaClient

from biom_type_plugin.validate import validate
from biom_type_plugin.summary import generate_html_summary
Expand Down Expand Up @@ -53,25 +53,26 @@ def execute_job(server_url, job_id, output_dir):
config.get('main', 'CLIENT_SECRET'),
server_cert=config.get('main', 'SERVER_CERT'))

# Request job information
# Request job information. If there is a problem retrieving the job
# information, the QiitaClient already raises an error
job_info = qclient.get_job_info(job_id)
# Check if we have received the job information so we can start it
if job_info and job_info['success']:
# Starting the heartbeat
qclient.start_heartbeat(job_id)
# Execute the given task
task_name = job_info['command']
task = TASK_DICT[task_name]
# Starting the heartbeat
qclient.start_heartbeat(job_id)
# Execute the given task
task_name = job_info['command']
task = TASK_DICT[task_name]

if not exists(output_dir):
makedirs(output_dir)
try:
payload = task(qclient, job_id, job_info['parameters'], output_dir)
except Exception:
exc_str = repr(traceback.format_exception(*sys.exc_info()))
error_msg = ("Error executing %s: \n%s" % (task_name, exc_str))
payload = format_payload(False, error_msg=error_msg)
# The job completed
qclient.complete_job(job_id, payload)
else:
raise RuntimeError("Can't get job (%s) information" % job_id)
if not exists(output_dir):
makedirs(output_dir)
try:
success, artifacts_info, error_msg = task(
qclient, job_id, job_info['parameters'], output_dir)
except Exception:
exc_str = repr(traceback.format_exception(*sys.exc_info()))
error_msg = ("Error executing %s: \n%s" % (task_name, exc_str))
success = False
artifacts_info = None

# The job completed
qclient.complete_job(job_id, success, error_msg=error_msg,
artifacts_info=artifacts_info)
39 changes: 14 additions & 25 deletions qiita_plugins/biom_type/biom_type_plugin/summary.py
Expand Up @@ -15,11 +15,9 @@
from StringIO import StringIO

import seaborn as sns
from qiita_client import format_payload


def generate_html_summary(qclient, job_id, parameters, out_dir,
return_html=False):
def generate_html_summary(qclient, job_id, parameters, out_dir):
"""Generates the HTML summary of a BIOM artifact
Parameters
Expand All @@ -32,30 +30,18 @@ def generate_html_summary(qclient, job_id, parameters, out_dir,
The parameter values to validate and create the artifact
out_dir : str
The path to the job's output directory
return_html : bool, optional
True will return the html str, useful for testing
Returns
-------
dict(, [str])
The results of the job and if return_html is True an array of str
Raises
------
ValueError
If there is any error gathering the information from the server
bool, None, str
Whether the job is successful
Ignored
The error message, if not successful
"""
# Step 1: gather file information from qiita using REST api
artifact_id = parameters['input_data']
qclient_url = "/qiita_db/artifacts/%s/filepaths/" % artifact_id
fps_info = qclient.get(qclient_url)
if not fps_info or not fps_info['success']:
error_msg = "Could not get artifact filepath information: %s"
if fps_info:
error_msg = error_msg % fps_info['error']
else:
error_msg = error_msg % "could not connect with the server"
raise ValueError(error_msg)

# if we get to this point of the code we are sure that this is a biom file
# and that it only has one element
Expand Down Expand Up @@ -107,9 +93,12 @@ def generate_html_summary(qclient, job_id, parameters, out_dir,
of.write('\n'.join(artifact_information))

# Step 3: add the new file to the artifact using REST api
reply = qclient.patch(qclient_url, 'add', '/html_summary/', value=of_fp)

payload = format_payload(
success=reply['success'], error_msg=reply['error'], artifacts_info=[])

return payload if not return_html else (payload, artifact_information)
success = True
error_msg = ""
try:
qclient.patch(qclient_url, 'add', '/html_summary/', value=of_fp)
except Exception as e:
success = False
error_msg = str(e)

return success, None, error_msg

0 comments on commit 9d734c0

Please sign in to comment.