Skip to content

Commit

Permalink
Merge pull request #1801 from josenavas/fix-rest-api-small-fixes
Browse files Browse the repository at this point in the history
A couple of small fixes
  • Loading branch information
antgonza committed Apr 21, 2016
2 parents 36c0fcd + cdea44e commit 44fcb32
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 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
1 change: 1 addition & 0 deletions qiita_plugins/biom_type/biom_type_plugin/plugin.py
Expand Up @@ -71,6 +71,7 @@ def execute_job(server_url, job_id, output_dir):
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,
Expand Down
7 changes: 5 additions & 2 deletions qiita_plugins/qiita_client/qiita_client/qiita_client.py
Expand Up @@ -79,8 +79,7 @@ def _format_payload(success, error_msg=None, artifacts_info=None):
'artifacts': dict of {str: {'artifact_type': str,
'filepaths': list of (str, str)}}
"""
if success:
error_msg = ''
if success and artifacts_info:
artifacts = {out_name: {'artifact_type': atype,
'filepaths': filepaths}
for out_name, atype, filepaths in artifacts_info}
Expand Down Expand Up @@ -357,6 +356,10 @@ def start_heartbeat(self, job_id):
The job id
"""
url = "/qiita_db/jobs/%s/heartbeat/" % job_id
# Execute the first heartbeat, since it is the one that sets the job
# to a running state - so make sure that other calls to the job work
# as expected
self.post(url, data='')
heartbeat_thread = threading.Thread(target=_heartbeat,
args=(self, url))
heartbeat_thread.daemon = True
Expand Down
1 change: 1 addition & 0 deletions qiita_plugins/target_gene/tgp/plugin.py
Expand Up @@ -72,6 +72,7 @@ def execute_job(server_url, job_id, output_dir):
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)
1 change: 1 addition & 0 deletions qiita_plugins/target_gene_type/target_gene_type/plugin.py
Expand Up @@ -75,6 +75,7 @@ def execute_job(server_url, job_id, output_dir):
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)

0 comments on commit 44fcb32

Please sign in to comment.