Skip to content

Commit aae765e

Browse files
committed
Prevent archiving if workflow is already archived
1 parent a290b3b commit aae765e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

beeflow/tests/test_wf_update.py

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_archive_workflow(tmpdir, mocker, test_function, expected_state):
1616
"""Regression test archive_workflow."""
1717
workdir = str(tmpdir / "workdir")
1818
db = mocker.MagicMock()
19+
db.workflows.get_workflow_state.return_value = "Running"
1920
mocker.patch("os.path.expanduser", return_value=str(tmpdir))
2021
mocker.patch(
2122
"beeflow.wf_manager.resources.wf_utils.get_workflow_dir", return_value=workdir
@@ -54,3 +55,18 @@ def test_archive_workflow(tmpdir, mocker, test_function, expected_state):
5455
mock_update_wf_status.assert_called_once_with("wf_id_test", expected_state)
5556
mock_remove_wf_dir.assert_called_once_with("wf_id_test")
5657
mock_log.assert_called_once_with("Removing Workflow Directory")
58+
59+
60+
@pytest.mark.parametrize("wf_state", ["Archived", "Archived/Failed"])
61+
def test_archive_archived_wf(mocker, wf_state):
62+
"""Don't archive workflow that is already archived."""
63+
db = mocker.MagicMock()
64+
db.workflows.get_workflow_state.return_value = wf_state
65+
mock_log_warning = mocker.patch("logging.Logger.warning")
66+
wf_update.archive_workflow(db, "id")
67+
mock_log_warning.assert_called_once_with(
68+
(
69+
"Attempted to archive workflow id which is already archived; "
70+
f"in state {wf_state}."
71+
)
72+
)

beeflow/wf_manager/resources/wf_update.py

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222

2323
def archive_workflow(db, wf_id, final_state=None):
2424
"""Archive a workflow after completion."""
25+
# this is the only way to retrieve wf state after archiving
26+
wf_db_state = db.workflows.get_workflow_state(wf_id)
27+
if wf_db_state.startswith("Archived"):
28+
# Don't archive a workflow that has already been archived
29+
log.warning((
30+
f"Attempted to archive workflow {wf_id} which is already archived; "
31+
f"in state {wf_db_state}."
32+
))
33+
return
2534
# Archive Config
2635
workflow_dir = wf_utils.get_workflow_dir(wf_id)
2736
shutil.copyfile(os.path.expanduser("~") + '/.config/beeflow/bee.conf',

0 commit comments

Comments
 (0)