Skip to content

Commit

Permalink
setting analysis to failed
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavlagneborg committed Dec 14, 2022
1 parent 130afac commit 556b999
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/store/test_store_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def test_set_analysis_uploaded(sample_store, timestamp_now: datetime):
# THEN the column uploaded_at should be updated
assert analysis_obj.uploaded_at == uploaded_at

def test_set_analysis_failed(sample_store):
"""Test setting analysis to failed for an analysis."""

# GIVEN a store with an analysis
analysis_obj: models.Analysis = sample_store.analyses().first()

# WHEN setting analysis to failed
sample_store.set_analysis_failed(case_id=analysis_obj.family, status="failed")

# THEN the column status should be updated with failed.
assert analysis_obj.status == "failed"

@pytest.mark.parametrize(
"family, expected_bool",
Expand Down
12 changes: 12 additions & 0 deletions trailblazer/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,15 @@ def put_set_analysis_uploaded():
return jsonify("Success! Update request sent"), 201
except Exception as error:
return jsonify(f"Exception: {error}"), 409

@blueprint.route("/set-analysis-failed", methods=["PUT"])
def put_set_analysis_failed():
content: Response.json = request.json

try:
store.set_analysis_failed(
case_id=content.get("case_id"), status=content.get("status")
)
return jsonify("Success! Update request sent"), 201
except Exception as error:
return jsonify(f"Exception: {error}"), 409
8 changes: 8 additions & 0 deletions trailblazer/store/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ def set_analysis_uploaded(self, case_id: str, uploaded_at: dt.datetime) -> None:
self.commit()
LOG.info(f"{analysis_obj.family} - uploaded at set to {uploaded_at}")


def set_analysis_failed(self, case_id: str, status: str):
"""Setting analysis status to failed."""
analysis_obj: models.Analysis = self.get_latest_analysis(case_id=case_id)
analysis_obj.status = status
self.commit()
LOG.info(f"{analysis_obj.family} - Status set to failed")

def delete_analysis(self, analysis_id: int, force: bool = False) -> None:
"""Delete the analysis output."""
analysis_obj = self.analysis(analysis_id=analysis_id)
Expand Down

0 comments on commit 556b999

Please sign in to comment.