Skip to content

Commit

Permalink
Merge pull request #611 from ebmdatalab/skip-cache-writing-if-running
Browse files Browse the repository at this point in the history
Do not write to the cache file if the run status is not final
  • Loading branch information
alarthast authored Oct 10, 2024
2 parents 3ca5fb5 + 8add4a0 commit aee24a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/workspace/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ def test_write_to_cache_file(mock_airlock_reporter, cache_path):
assert json.loads(cache_path.read_text()) == CACHE


@pytest.mark.parametrize("conclusion", ["running", "queued"])
@patch("workspace.workflows.jobs.RepoWorkflowReporter.get_conclusion_for_run")
def test_pending_status_not_written_to_cache_file(
mock_get_conclusion_for_run, mock_airlock_reporter, cache_path, conclusion
):
mock_get_conclusion_for_run.return_value = conclusion
with patch("workspace.workflows.jobs.CACHE_PATH", cache_path):
mock_airlock_reporter.get_latest_conclusions()
assert not cache_path.exists()


@pytest.mark.parametrize(
"run, conclusion",
[
Expand Down
5 changes: 4 additions & 1 deletion workspace/workflows/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def get_latest_conclusions(self) -> dict:
# To be consistent with the JSON file which has the IDs as strings
"conclusions": {str(k): v for k, v in conclusions.items()},
}
self.write_cache_to_file()

pending = "running" in conclusions.values() or "queued" in conclusions.values()
if not pending: # Only write cache to file if the status is final
self.write_cache_to_file()
return conclusions

@staticmethod
Expand Down

0 comments on commit aee24a4

Please sign in to comment.