Skip to content

Commit daf3319

Browse files
authored
1 parent af2ce16 commit daf3319

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

qiita_db/processing_job.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,6 +2392,20 @@ def add(self, dflt_params, connections=None, req_params=None,
23922392
with qdb.sql_connection.TRN:
23932393
self._raise_if_not_in_construction()
23942394

2395+
# checking that the new number of artifacts is not above
2396+
# max_artifacts_in_workflow
2397+
current_artifacts = sum(
2398+
[len(j.command.outputs) for j in self.graph.nodes()])
2399+
to_add_artifacts = len(dflt_params.command.outputs)
2400+
total_artifacts = current_artifacts + to_add_artifacts
2401+
max_artifacts = qdb.util.max_artifacts_in_workflow()
2402+
if total_artifacts > max_artifacts:
2403+
raise ValueError(
2404+
"Cannot add new job because it will create more "
2405+
f"artifacts (current: {current_artifacts} + new: "
2406+
f"{to_add_artifacts} = {total_artifacts}) that what is "
2407+
f"allowed in a single workflow ({max_artifacts})")
2408+
23952409
if connections:
23962410
# The new Job depends on previous jobs in the workflow
23972411
req_params = req_params if req_params else {}

qiita_db/support_files/patches/90.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Jan 9, 2024
2+
-- add control of max artifacts in analysis to the settings
3+
-- using 35 as default considering that a core div creates ~17 so allowing
4+
-- for 2 of those + 1
5+
ALTER TABLE settings
6+
ADD COLUMN IF NOT EXISTS max_artifacts_in_workflow INT DEFAULT 35;

qiita_db/test/test_processing_job.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,18 @@ def test_add_error(self):
12051205
qdb.exceptions.QiitaDBOperationNotPermittedError):
12061206
qdb.processing_job.ProcessingWorkflow(1).add({}, None)
12071207

1208+
# test that the qdb.util.max_artifacts_in_workflow
1209+
with qdb.sql_connection.TRN:
1210+
qdb.sql_connection.perform_as_transaction(
1211+
"UPDATE settings set max_artifacts_in_workflow = 1")
1212+
with self.assertRaisesRegex(
1213+
ValueError, "Cannot add new job because it will create "
1214+
"more artifacts "):
1215+
qdb.processing_job.ProcessingWorkflow(2).add(
1216+
qdb.software.DefaultParameters(1),
1217+
req_params={'input_data': 1}, force=True)
1218+
qdb.sql_connection.TRN.rollback()
1219+
12081220
def test_remove(self):
12091221
exp_command = qdb.software.Command(1)
12101222
json_str = (

qiita_db/test/test_util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def test_max_preparation_samples(self):
4545
obs = qdb.util.max_preparation_samples()
4646
self.assertEqual(obs, 800)
4747

48+
def test_max_artifacts_in_workflow(self):
49+
"""Test that we get the correct max_artifacts_in_workflow"""
50+
obs = qdb.util.max_artifacts_in_workflow()
51+
self.assertEqual(obs, 35)
52+
4853
def test_filepath_id_to_object_id(self):
4954
# filepaths 1, 2 belongs to artifact 1
5055
self.assertEqual(qdb.util.filepath_id_to_object_id(1), 1)

qiita_db/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,20 @@ def max_preparation_samples():
416416
return qdb.sql_connection.TRN.execute_fetchlast()
417417

418418

419+
def max_artifacts_in_workflow():
420+
r"""Returns the max number of artifacts allowed in a single workflow
421+
422+
Returns
423+
-------
424+
int
425+
The max number of artifacts allowed in a single workflow
426+
"""
427+
with qdb.sql_connection.TRN:
428+
qdb.sql_connection.TRN.add(
429+
"SELECT max_artifacts_in_workflow FROM settings")
430+
return qdb.sql_connection.TRN.execute_fetchlast()
431+
432+
419433
def compute_checksum(path):
420434
r"""Returns the checksum of the file pointed by path
421435

0 commit comments

Comments
 (0)