Skip to content

Commit

Permalink
❌ add REJECTED choice and cli to reject analyses
Browse files Browse the repository at this point in the history
  • Loading branch information
juanesarango committed Oct 24, 2023
1 parent 31b715f commit 29347b3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions isabl_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AbstractApplication: # pylint: disable=too-many-public-methods
# Analyses in these status won't be prepared for submission. To re-rerun SUCCEEDED
# analyses see unique_analysis_per_individual. To re-rerun failed analyses use
# either --force or --restart.
skip_status = {"FAILED", "FINISHED", "STARTED", "SUBMITTED", "SUCCEEDED"}
skip_status = {"FAILED", "FINISHED", "STARTED", "SUBMITTED", "SUCCEEDED", "REJECTED"}

# If any of these errors is raised during the command generation process, the
# submission will continue. Errors or valdation messages are presented at the end.
Expand Down Expand Up @@ -957,7 +957,7 @@ def run_analyses(self, analyses, commit, force, restart, local):
api.patch_analysis_status(i, "STAGED")

# trash analysis and create outdir again
elif force and i["status"] not in {"SUCCEEDED", "FINISHED"}:
elif force and i["status"] not in {"SUCCEEDED", "FINISHED", "REJECTED"}:
system_settings.TRASH_ANALYSIS_STORAGE(i)
utils.makedirs(i["storage_url"])

Expand Down
10 changes: 10 additions & 0 deletions isabl_cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,13 @@ def run_signals(endpoint, filters, signals):

for i in api.get_instances(endpoint, **filters):
api._run_signals(endpoint, i, signals, raise_error=True, create_record=False)


@click.command(hidden=True)
@options.ANALYSIS_PRIMARY_KEY
@click.option("--reason", help="Rejection reason. (Will be stored in Analysis.notes)")
def reject_analysis(key, reason):
"""Patch an analysis status as REJECTED, providing the rejection reason."""
analysis = api.get_instance("analyses", key)
api.patch_analysis_status(analysis, "REJECTED")
api.patch_instance("analyses", key, {"notes": reason})
1 change: 1 addition & 0 deletions isabl_cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _get_experiments(filter_tuples):
"STARTED",
"SUBMITTED",
"SUCCEEDED",
"REJECTED",
]
),
)
Expand Down
22 changes: 19 additions & 3 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_get_bams():
assert "/hello/mars" in result.output


def test_get_data(tmpdir):
def test_get_data():
runner = CliRunner()
experiment = api.create_instance("experiments", **factories.ExperimentFactory())
experiment = data.update_storage_url("experiments", experiment.pk)
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_run_web_signals():


def test_process_finished_tags(tmpdir):
# check that a tagged analysis does NOT get processed to FINISHED
"""Check that a tagged analysis does NOT get processed to FINISHED."""
analysis = api.create_instance(
"analyses",
project_level_analysis=factories.ProjectFactory(),
Expand All @@ -310,7 +310,7 @@ def test_process_finished_tags(tmpdir):


def test_force_process_finished_tags(tmpdir):
# check that a tagged analysis does get processed to FINISHED when forced
"""Check that a tagged analysis does get processed to FINISHED when forced."""
analysis = api.create_instance(
"analyses",
project_level_analysis=factories.ProjectFactory(),
Expand All @@ -324,3 +324,19 @@ def test_force_process_finished_tags(tmpdir):
print(result.output)
analysis = api.get_instance("analyses", analysis["pk"])
assert analysis["status"] == "SUCCEEDED"


def test_rejected_analysis(tmpdir):
"""Check an analysis can be rejected using the command cli."""
analysis = api.create_instance(
"analyses",
status="FINISHED",
**factories.AnalysisFactory(ran_by=None),
)
runner = CliRunner()
rejection_reason = "This analysis is FAKE."
args = ["--key", analysis["pk"], "--reason", rejection_reason]
runner.invoke(commands.reject_analysis, args, catch_exceptions=False)
analysis = api.get_instance("analyses", analysis["pk"])
assert analysis["status"] == "REJECTED"
assert analysis["notes"] == rejection_reason

0 comments on commit 29347b3

Please sign in to comment.