Skip to content

Commit

Permalink
move delete_work config option from task_runtime to file_io
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Apr 13, 2020
1 parent fecdc91 commit 8632014
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions WDL/runtime/config_templates/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,21 @@ copy_input_files = false
# Each succeeded run directory has an "output_links/" folder containing (by default) a symbolic
# link to each output file in its original working location. If output_hardlinks is true, then
# output_links/ is populated with hardlinks instead of symlinks. Beware the potential confusion
# arising from files with multiple hardlinks! See also [task_runtime] delete_work, below.
# arising from files with multiple hardlinks! See also delete_work, below.
output_hardlinks = false
# Delete task working directory upon completion. The task container's working directory is a
# bind-mounted host directory, so files written into it are left behind after the container is torn
# down. If tasks write large non-output files into their working directory (instead of $TMPDIR as
# they should), then it can be useful to delete them automatically.
# Values:
# false = never delete (default)
# success = delete working directories of succeeded tasks
# failure = " failed tasks
# always = " both succeeded and failed tasks
# The "success" and "always" settings require output_hardlinks, above, to be true; otherwise,
# output files would be deleted too. Input/output JSON, logs, and stdout/stderr are always retained
# in the task run directory (above the container working directory).
delete_work = false


[task_runtime]
Expand All @@ -66,19 +79,6 @@ defaults = {
# Run the command script as the invoking user's uid:gid instead of usually running as root. More
# secure, but interferes with commands that assume root access e.g. apt-get. --as-me
as_user = false
# Delete task working directory upon completion. The task container's working directory is a
# bind-mounted host directory, so files written into it are left behind after the container is torn
# down. If tasks write large non-output files into their working directory (instead of $TMPDIR as
# they should), then it can be useful to delete them automatically.
# Values:
# false = never delete (default)
# success = delete working directories of succeeded tasks
# failure = " failed tasks
# always = " both succeeded and failed tasks
# The "success" and "always" settings require [file_io] output_hardlinks, above, to be true;
# otherwise, output files would be deleted too. Input/output JSON, logs, and stdout/stderr are
# always retained in the task run directory (above the container working directory).
delete_work = false


[download_cache]
Expand Down
6 changes: 3 additions & 3 deletions WDL/runtime/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def _try_task(
logger,
interruptions + retries - 1,
delete_work=(
cfg["task_runtime"]["delete_work"].strip().lower() in ["always", "failure"]
cfg["file_io"]["delete_work"].strip().lower() in ["always", "failure"]
),
)

Expand Down Expand Up @@ -1280,11 +1280,11 @@ def map_files(v: Value.Base, dn: str) -> Value.Base:


def _delete_work(cfg: config.Loader, logger: logging.Logger, run_dir: str, success: bool) -> None:
opt = cfg["task_runtime"]["delete_work"].strip().lower()
opt = cfg["file_io"]["delete_work"].strip().lower()
if opt == "always" or (success and opt == "success") or (not success and opt == "failure"):
if success and not cfg["file_io"].get_bool("output_hardlinks"):
logger.warning(
"ignoring configuration [task_runtime] delete_work because it requires [file_io] output_hardlinks = true"
"ignoring configuration [file_io] delete_work because it requires also output_hardlinks = true"
)
return
for dn in ["write_", "work", "failed_tries"]:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_4taskrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,15 @@ def test_delete_work(self):
outfile.write("Ben\n")
inputs = {"files": [os.path.join(self._dir, "alyssa.txt"), os.path.join(self._dir, "ben.txt")]}
cfg = WDL.runtime.config.Loader(logging.getLogger(self.id()), [])
cfg.override({"file_io": {"output_hardlinks": True}, "task_runtime": {"delete_work": "success"}})
cfg.override({"file_io": {"output_hardlinks": True, "delete_work": "success"}})
output = self._test_task(txt, inputs, cfg=cfg)
self.assertFalse(os.path.isdir(os.path.join(self._rundir, "work")))
self.assertFalse(os.path.isdir(os.path.join(self._rundir, "write_")))
for fn in output["outfiles"]:
self.assertTrue(os.path.isfile(fn) and not os.path.islink(fn))

cfg = WDL.runtime.config.Loader(logging.getLogger(self.id()), [])
cfg.override({"file_io": {"output_hardlinks": False}, "task_runtime": {"delete_work": "success"}})
cfg.override({"file_io": {"output_hardlinks": False, "delete_work": "success"}})
output = self._test_task(txt, inputs, cfg=cfg)
self.assertTrue(os.path.isfile(os.path.join(self._rundir, "work", "foo.txt")))

Expand Down
2 changes: 1 addition & 1 deletion tests/test_6workflowrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def test_retry(self):
self.assertGreaterEqual(outputs["finish_time"], outputs["start_time"] + 20)
self.assertTrue(os.path.isfile(os.path.join(self._rundir, "call-finish", "failed_tries", "0", "work", "iwuzhere")))
cfg = WDL.runtime.config.Loader(logging.getLogger(self.id()), [])
cfg.override({"task_runtime": {"delete_work": "failure", "_mock_interruptions": 2}})
cfg.override({"file_io": {"delete_work": "failure"}, "task_runtime": {"_mock_interruptions": 2}})
outputs = self._test_workflow(txt, cfg=cfg)
self.assertGreaterEqual(outputs["finish_time"], outputs["start_time"] + 20)
self.assertFalse(os.path.isdir(os.path.join(self._rundir, "call-finish", "failed_tries")))

0 comments on commit 8632014

Please sign in to comment.