Skip to content

Commit 9bba2bd

Browse files
Merge pull request #3205 from antgonza/allow-summary-update
allow artifact summary update
2 parents 60f3cc1 + 203005f commit 9bba2bd

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

qiita_db/artifact.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,10 +1131,12 @@ def set_html_summary(self, html_fp, support_dir=None):
11311131
the HTML file
11321132
"""
11331133
with qdb.sql_connection.TRN:
1134-
if self.html_summary_fp:
1135-
# Delete the current HTML summary
1134+
old_summs = self.html_summary_fp
1135+
to_delete_fps = []
1136+
if old_summs:
1137+
# Delete from the DB current HTML summary; below we will remove
1138+
# files, if necessary
11361139
to_delete_ids = []
1137-
to_delete_fps = []
11381140
for x in self.filepaths:
11391141
if x['fp_type'] in ('html_summary', 'html_summary_dir'):
11401142
to_delete_ids.append([x['fp_id']])
@@ -1146,17 +1148,6 @@ def set_html_summary(self, html_fp, support_dir=None):
11461148
# From the filepath table
11471149
sql = "DELETE FROM qiita.filepath WHERE filepath_id=%s"
11481150
qdb.sql_connection.TRN.add(sql, to_delete_ids, many=True)
1149-
# And from the filesystem only after the transaction is
1150-
# successfully completed (after commit)
1151-
1152-
def path_cleaner(fps):
1153-
for fp in fps:
1154-
if isfile(fp):
1155-
remove(fp)
1156-
else:
1157-
rmtree(fp)
1158-
qdb.sql_connection.TRN.add_post_commit_func(
1159-
path_cleaner, to_delete_fps)
11601151

11611152
# Add the new HTML summary
11621153
filepaths = [(html_fp, 'html_summary')]
@@ -1171,6 +1162,19 @@ def path_cleaner(fps):
11711162
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
11721163
qdb.sql_connection.TRN.execute()
11731164

1165+
# to avoid deleting potentially necessary files, we are going to add
1166+
# that check after the previous transaction is commited
1167+
if to_delete_fps:
1168+
for x in self.filepaths:
1169+
if x['fp'] in to_delete_fps:
1170+
to_delete_fps.remove(x['fp'])
1171+
1172+
for fp in to_delete_fps:
1173+
if isfile(fp):
1174+
remove(fp)
1175+
else:
1176+
rmtree(fp)
1177+
11741178
@property
11751179
def parents(self):
11761180
"""Returns the parents of the artifact

qiita_db/test/test_artifact.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,10 @@ def test_html_summary_setter(self):
13521352
if x['fp_type'] == 'html_summary_dir']
13531353
self.assertEqual(summary_dir, [])
13541354

1355+
# let's check if we update, we do _not_ remove the files
1356+
a.set_html_summary(exp3)
1357+
self.assertTrue(exists(a.html_summary_fp[1]))
1358+
13551359
def test_descendants_with_jobs_one_element(self):
13561360
artifact = qdb.artifact.Artifact.create(
13571361
self.filepaths_root, 'FASTQ', prep_template=self.prep_template)

qiita_pet/handlers/artifact_handlers/base_handlers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def artifact_summary_get_request(user, artifact_id):
242242
'errored_summary_jobs': errored_summary_jobs}
243243

244244

245-
def artifact_summary_post_request(user, artifact_id):
245+
def artifact_summary_post_request(user, artifact_id, force_creation=False):
246246
"""Launches the HTML summary generation and returns the job information
247247
248248
Parameters
@@ -251,6 +251,8 @@ def artifact_summary_post_request(user, artifact_id):
251251
The user making the request
252252
artifact_id : int or str
253253
The artifact id
254+
force_creation : bool
255+
If all jobs should be ignored and it should force creation
254256
255257
Returns
256258
-------
@@ -267,7 +269,7 @@ def artifact_summary_post_request(user, artifact_id):
267269
command = Command.get_html_generator(artifact.artifact_type)
268270
jobs = artifact.jobs(cmd=command)
269271
jobs = [j for j in jobs if j.status in ['queued', 'running', 'success']]
270-
if jobs:
272+
if not force_creation and jobs:
271273
# The HTML summary is either being generated or already generated.
272274
# Return the information of that job so we only generate the HTML
273275
# once - Magic number 0 -> we are ensuring that there is only one

0 commit comments

Comments
 (0)