Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cylc clean while cat-log running #5359

Merged
merged 8 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cylc/flow/cfgspec/globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,8 @@ def default_for(
"[remote]retrieve job logs retry delays")}
''')
Conf('tail command template',
VDR.V_STRING, 'tail -n +1 -F %(filename)s', desc=f'''
VDR.V_STRING, 'tail -n +1 --follow=name -F %(filename)s',
desc=f'''
A command template (with ``%(filename)s`` substitution) to
tail-follow job logs this platform, by ``cylc cat-log``.

Expand Down
30 changes: 26 additions & 4 deletions cylc/flow/pathutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Functions to return paths to common workflow files and directories."""

import errno
import os
from pathlib import Path
import re
from shutil import rmtree
from time import sleep
from typing import Dict, Iterable, Set, Union, Optional, Any

from cylc.flow import LOG
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.exceptions import (
InputError, WorkflowFilesError, handle_rmtree_err
FileRemovalError, InputError, WorkflowFilesError
)
from cylc.flow.platforms import get_localhost_install_target

Expand Down Expand Up @@ -297,15 +299,35 @@ def remove_dir_and_target(path: Union[Path, str]) -> None:
"Removing symlink and its target directory: "
f"{path} -> {target}"
)
rmtree(target, onerror=handle_rmtree_err)
_rmtree(target)
else:
LOG.info(f'Removing broken symlink: {path}')
os.remove(path)
elif not os.path.exists(path):
raise FileNotFoundError(path)
else:
LOG.info(f'Removing directory: {path}')
rmtree(path, onerror=handle_rmtree_err)
_rmtree(path)


def _rmtree(target: Union[Path, str],
retries: int = 5,
sleep_time: float = 0.5):
"""Make rmtree more robust to nfs issues.

shutil.rmtree will be retried (default 5 times)
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
"""
for _try_num in range(retries):
try:
rmtree(target)
return
except OSError as exc:
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
if exc.errno == errno.ENOTEMPTY:
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
err = exc
sleep(sleep_time)
else:
raise
raise FileRemovalError(err)


def remove_dir_or_file(path: Union[Path, str]) -> None:
Expand All @@ -325,7 +347,7 @@ def remove_dir_or_file(path: Union[Path, str]) -> None:
os.remove(path)
else:
LOG.info(f"Removing directory: {path}")
rmtree(path, onerror=handle_rmtree_err)
_rmtree(path)


def remove_empty_parents(
Expand Down
10 changes: 6 additions & 4 deletions cylc/flow/scripts/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@ async def run(*ids: str, opts: 'Values') -> None:
if multi_mode and not opts.skip_interactive:
prompt(workflows) # prompt for approval or exit

failed = []
failed = {}
for workflow in sorted(workflows):
try:
init_clean(workflow, opts)
except Exception as exc:
failed.append(workflow)
LOG.warning(exc)
failed[workflow] = exc
if failed:
raise CylcError(f"Clean failed: {', '.join(failed)}")
msg = "Clean failed:"
for workflow, exc_message in failed.items():
msg += f"\nWorkflow: {workflow}\nError: {exc_message}"
raise CylcError(msg)


@cli_function(get_option_parser)
Expand Down