Skip to content

Commit 85f6ec7

Browse files
josenavasantgonza
authored andcommitted
Analysis refactor misc (#2161)
* Fixing race condition * Removing unused code and fixing typo * Hiding job step if success * Showing loading gif and fixing typo
1 parent 7327507 commit 85f6ec7

File tree

10 files changed

+14
-610
lines changed

10 files changed

+14
-610
lines changed

qiita_pet/handlers/analysis_handlers/base_handlers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
class CreateAnalysisHandler(BaseHandler):
2323
@authenticated
24-
@execute_as_transaction
2524
def post(self):
2625
name = self.get_argument('name')
2726
desc = self.get_argument('description')

qiita_pet/handlers/api_proxy/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
study_tags_request)
3131
from .artifact import (artifact_graph_get_req, artifact_types_get_req,
3232
artifact_post_req, artifact_get_req,
33-
artifact_status_put_req,
34-
artifact_summary_get_request, artifact_get_prep_req,
35-
artifact_summary_post_request, artifact_patch_request)
33+
artifact_status_put_req, artifact_get_prep_req,
34+
artifact_patch_request)
3635
from .ontology import ontology_patch_handler
3736
from .processing import (
3837
list_commands_handler_get_req, process_artifact_handler_get_req,
@@ -62,7 +61,6 @@
6261
'study_tags_request', 'study_tags_patch_request',
6362
'study_get_tags_request',
6463
'prep_template_patch_req', 'ontology_patch_handler',
65-
'artifact_summary_get_request', 'artifact_summary_post_request',
6664
'list_commands_handler_get_req', 'process_artifact_handler_get_req',
6765
'list_options_handler_get_req', 'workflow_handler_post_req',
6866
'workflow_handler_patch_req', 'workflow_run_post_req',

qiita_pet/handlers/api_proxy/artifact.py

Lines changed: 1 addition & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# The full license is in the file LICENSE, distributed with this software.
77
# -----------------------------------------------------------------------------
8-
from os.path import join, basename
8+
from os.path import join
99
from functools import partial
1010
from json import dumps
1111

@@ -28,194 +28,6 @@
2828
PREP_TEMPLATE_KEY_FORMAT = 'prep_template_%s'
2929

3030

31-
def artifact_summary_get_request(user_id, artifact_id):
32-
"""Returns the information for the artifact summary page
33-
34-
Parameters
35-
----------
36-
user_id : str
37-
The user making the request
38-
artifact_id : int or str
39-
The artifact id
40-
41-
Returns
42-
-------
43-
dict of objects
44-
A dictionary containing the artifact summary information
45-
{'status': str,
46-
'message': str,
47-
'name': str,
48-
'summary': str,
49-
'job': list of [str, str, str]}
50-
"""
51-
artifact_id = int(artifact_id)
52-
artifact = Artifact(artifact_id)
53-
54-
access_error = check_access(artifact.study.id, user_id)
55-
if access_error:
56-
return access_error
57-
58-
user = User(user_id)
59-
visibility = artifact.visibility
60-
summary = artifact.html_summary_fp
61-
job_info = None
62-
errored_jobs = []
63-
processing_jobs = []
64-
for j in artifact.jobs():
65-
if j.command.software.type == "artifact transformation":
66-
status = j.status
67-
if status == 'success':
68-
continue
69-
j_msg = j.log.msg if status == 'error' else None
70-
processing_jobs.append(
71-
[j.id, j.command.name, j.status, j.step, j_msg])
72-
73-
# Check if the HTML summary exists
74-
if summary:
75-
with open(summary[1]) as f:
76-
summary = f.read()
77-
else:
78-
# Check if the summary is being generated
79-
command = Command.get_html_generator(artifact.artifact_type)
80-
all_jobs = set(artifact.jobs(cmd=command))
81-
jobs = [j for j in all_jobs if j.status in ['queued', 'running']]
82-
errored_jobs = [(j.id, j.log.msg)
83-
for j in all_jobs if j.status in ['error']]
84-
if jobs:
85-
# There is already a job generating the HTML. Also, there should be
86-
# at most one job, because we are not allowing here to start more
87-
# than one
88-
job = jobs[0]
89-
job_info = [job.id, job.status, job.step]
90-
91-
buttons = []
92-
btn_base = (
93-
'<button onclick="if (confirm(\'Are you sure you want to %s '
94-
'artifact id: {0}?\')) {{ set_artifact_visibility(\'%s\', {0}) }}" '
95-
'class="btn btn-primary btn-sm">%s</button>').format(artifact_id)
96-
97-
if qiita_config.require_approval:
98-
if visibility == 'sandbox':
99-
# The request approval button only appears if the artifact is
100-
# sandboxed and the qiita_config specifies that the approval should
101-
# be requested
102-
buttons.append(
103-
btn_base % ('request approval for', 'awaiting_approval',
104-
'Request approval'))
105-
106-
elif user.level == 'admin' and visibility == 'awaiting_approval':
107-
# The approve artifact button only appears if the user is an admin
108-
# the artifact is waiting to be approvaed and the qiita config
109-
# requires artifact approval
110-
buttons.append(btn_base % ('approve', 'private',
111-
'Approve artifact'))
112-
113-
if visibility == 'private':
114-
# The make public button only appears if the artifact is private
115-
buttons.append(btn_base % ('make public', 'public', 'Make public'))
116-
117-
# The revert to sandbox button only appears if the artifact is not
118-
# sandboxed nor public
119-
if visibility not in {'sandbox', 'public'}:
120-
buttons.append(btn_base % ('revert to sandbox', 'sandbox',
121-
'Revert to sandbox'))
122-
123-
if user.level == 'admin':
124-
if artifact.can_be_submitted_to_ebi:
125-
if not artifact.is_submitted_to_ebi:
126-
buttons.append(
127-
'<a class="btn btn-primary btn-sm" '
128-
'href="/ebi_submission/%d">'
129-
'<span class="glyphicon glyphicon-export"></span>'
130-
' Submit to EBI</a>' % artifact_id)
131-
if artifact.can_be_submitted_to_vamps:
132-
if not artifact.is_submitted_to_vamps:
133-
buttons.append(
134-
'<a class="btn btn-primary btn-sm" href="/vamps/%d">'
135-
'<span class="glyphicon glyphicon-export"></span>'
136-
' Submit to VAMPS</a>' % artifact_id)
137-
138-
files = [(f_id, "%s (%s)" % (basename(fp), f_type.replace('_', ' ')))
139-
for f_id, fp, f_type in artifact.filepaths
140-
if f_type != 'directory']
141-
142-
# TODO: https://github.com/biocore/qiita/issues/1724 Remove this hardcoded
143-
# values to actually get the information from the database once it stores
144-
# the information
145-
if artifact.artifact_type in ['SFF', 'FASTQ', 'FASTA', 'FASTA_Sanger',
146-
'per_sample_FASTQ']:
147-
# If the artifact is one of the "raw" types, only the owner of the
148-
# study and users that has been shared with can see the files
149-
if not artifact.study.has_access(user, no_public=True):
150-
files = []
151-
152-
processing_parameters = (artifact.processing_parameters.values
153-
if artifact.processing_parameters is not None
154-
else {})
155-
156-
return {'status': 'success',
157-
'message': '',
158-
'name': artifact.name,
159-
'summary': summary,
160-
'job': job_info,
161-
'errored_jobs': errored_jobs,
162-
'processing_jobs': processing_jobs,
163-
'visibility': visibility,
164-
'buttons': ' '.join(buttons),
165-
'files': files,
166-
'editable': artifact.study.can_edit(user),
167-
'study_id': artifact.study.id,
168-
'prep_id': artifact.prep_templates[0].id,
169-
'processing_parameters': processing_parameters}
170-
171-
172-
def artifact_summary_post_request(user_id, artifact_id):
173-
"""Launches the HTML summary generation and returns the job information
174-
175-
Parameters
176-
----------
177-
user_id : str
178-
The user making the request
179-
artifact_id : int or str
180-
The artifact id
181-
182-
Returns
183-
-------
184-
dict of objects
185-
A dictionary containing the artifact summary information
186-
{'status': str,
187-
'message': str,
188-
'job': list of [str, str, str]}
189-
"""
190-
artifact_id = int(artifact_id)
191-
artifact = Artifact(artifact_id)
192-
193-
access_error = check_access(artifact.study.id, user_id)
194-
if access_error:
195-
return access_error
196-
197-
# Check if the summary is being generated or has been already generated
198-
command = Command.get_html_generator(artifact.artifact_type)
199-
jobs = artifact.jobs(cmd=command)
200-
jobs = [j for j in jobs if j.status in ['queued', 'running', 'success']]
201-
if jobs:
202-
# The HTML summary is either being generated or already generated.
203-
# Return the information of that job so we only generate the HTML
204-
# once
205-
job = jobs[0]
206-
else:
207-
# Create a new job to generate the HTML summary and return the newly
208-
# created job information
209-
job = ProcessingJob.create(
210-
User(user_id),
211-
Parameters.load(command, values_dict={'input_data': artifact_id}))
212-
job.submit()
213-
214-
return {'status': 'success',
215-
'message': '',
216-
'job': [job.id, job.status, job.step]}
217-
218-
21931
def artifact_get_req(user_id, artifact_id):
22032
"""Returns all base information about an artifact
22133

0 commit comments

Comments
 (0)