Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3327 #3346

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions qiita_db/processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,20 @@ def add(self, dflt_params, connections=None, req_params=None,
with qdb.sql_connection.TRN:
self._raise_if_not_in_construction()

# checking that the new number of artifacts is not above
# max_artifacts_in_workflow
current_artifacts = sum(
[len(j.command.outputs) for j in self.graph.nodes()])
to_add_artifacts = len(dflt_params.command.outputs)
total_artifacts = current_artifacts + to_add_artifacts
max_artifacts = qdb.util.max_artifacts_in_workflow()
if total_artifacts > max_artifacts:
raise ValueError(
"Cannot add new job because it will create more "
f"artifacts (current: {current_artifacts} + new: "
f"{to_add_artifacts} = {total_artifacts}) that what is "
f"allowed in a single workflow ({max_artifacts})")

if connections:
# The new Job depends on previous jobs in the workflow
req_params = req_params if req_params else {}
Expand Down
6 changes: 6 additions & 0 deletions qiita_db/support_files/patches/90.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Jan 9, 2024
-- add control of max artifacts in analysis to the settings
-- using 35 as default considering that a core div creates ~17 so allowing
-- for 2 of those + 1
ALTER TABLE settings
ADD COLUMN IF NOT EXISTS max_artifacts_in_workflow INT DEFAULT 35;
12 changes: 12 additions & 0 deletions qiita_db/test/test_processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,18 @@ def test_add_error(self):
qdb.exceptions.QiitaDBOperationNotPermittedError):
qdb.processing_job.ProcessingWorkflow(1).add({}, None)

# test that the qdb.util.max_artifacts_in_workflow
with qdb.sql_connection.TRN:
qdb.sql_connection.perform_as_transaction(
"UPDATE settings set max_artifacts_in_workflow = 1")
with self.assertRaisesRegex(
ValueError, "Cannot add new job because it will create "
"more artifacts "):
qdb.processing_job.ProcessingWorkflow(2).add(
qdb.software.DefaultParameters(1),
req_params={'input_data': 1}, force=True)
qdb.sql_connection.TRN.rollback()

def test_remove(self):
exp_command = qdb.software.Command(1)
json_str = (
Expand Down
5 changes: 5 additions & 0 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def test_max_preparation_samples(self):
obs = qdb.util.max_preparation_samples()
self.assertEqual(obs, 800)

def test_max_artifacts_in_workflow(self):
"""Test that we get the correct max_artifacts_in_workflow"""
obs = qdb.util.max_artifacts_in_workflow()
self.assertEqual(obs, 35)

def test_filepath_id_to_object_id(self):
# filepaths 1, 2 belongs to artifact 1
self.assertEqual(qdb.util.filepath_id_to_object_id(1), 1)
Expand Down
14 changes: 14 additions & 0 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@ def max_preparation_samples():
return qdb.sql_connection.TRN.execute_fetchlast()


def max_artifacts_in_workflow():
r"""Returns the max number of artifacts allowed in a single workflow

Returns
-------
int
The max number of artifacts allowed in a single workflow
"""
with qdb.sql_connection.TRN:
qdb.sql_connection.TRN.add(
"SELECT max_artifacts_in_workflow FROM settings")
return qdb.sql_connection.TRN.execute_fetchlast()


def compute_checksum(path):
r"""Returns the checksum of the file pointed by path

Expand Down
Loading